gpt4 book ai didi

c++ - 为什么在 win32 中有不同的 TEXT like macros for same thing?

转载 作者:可可西里 更新时间:2023-11-01 13:50:26 24 4
gpt4 key购买 nike

我想知道为什么会出现 T、TEXT、_TEXT、__TEXT 或 __T 等宏,而它们最终都做同样的事情。

如果定义了 UNICODE,则将“字符串”映射到 L“字符串”。

感谢您的回答。在更实际的方法中,有人可以向我解释下面给出的代码的行为吗?

#include <stdio.h>
#include <conio.h>
#include <tchar.h> // For _T and _TEXT
#include <windows.h> // For __TEXT

int __cdecl main ()

{

printf ("%s", _TEXT(__FILE__ )); // Works fine

printf ("%s", _T(__FILE__)); // Works fine

printf ("%s", __TEXT(__FILE__ )); // error C2065: 'L__FILE__': undeclared identifier

_getwch();

}

更新:我认为我的代码与 C 预处理器标记化有关。我为此发布了一个单独的问题。谢谢。

最佳答案

因为“神秘”事物经常出现这种情况,Raymond Chen gives some information (强调):

So what's with all these different ways of saying the same thing? There's actually a method behind the madness.

The plain versions without the underscore affect the character set the Windows header files treat as default. So if you define UNICODE, then GetWindowText will map to GetWindowTextW instead of GetWindowTextA, for example. Similarly, the TEXT macro will map to L"..." instead of "...".

The versions with the underscore affect the character set the C runtime header files treat as default. So if you define _UNICODE, then _tcslen will map to wcslen instead of strlen, for example. Similarly, the _TEXT macro will map to L"..." instead of "...". What about _T? Okay, I don't know about that one. Maybe it was just to save somebody some typing.

关于c++ - 为什么在 win32 中有不同的 TEXT like macros for same thing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8314552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com