简体   繁体   English

宏扩展中的语法错误

[英]Syntax error in Macro expansion

How does the TEXT("x") macro expand to L"x" if unicode is defined and "x" if unicode is not defined because when I try to compile the following code it says "error #1049: Syntax error in macro parameters." 如果定义了unicode,则TEXT(“ x”)宏如何扩展为L“ x”;如果未定义unicode,则如何扩展为“ x”,因为当我尝试编译以下代码时,它说“错误#1049:宏参数中的语法错误” ”。

#define T("x") "x"

int main()
{
}

Lookup the tchar.h header in your installation. 在安装中查找tchar.h标头。 You'd get something like the following: 您将获得如下内容:

#define __T(x)      L ## x

In Unicode mode, the above macro pastes an L and a string argument together. 在Unicode模式下,上面的宏将L和字符串参数粘贴在一起。 In ASCII mode, there is no prefix to paste so it goes simply as: 在ASCII模式下,没有要粘贴的前缀,因此它简单地如下所示:

#define __T(x)      x

Note that you invoke this macro indirectly, via another macro -- _T() (with a single underscore) and pass a string literal as argument. 请注意,您可以通过另一个宏_T() (带有单个下划线)间接调用此宏,并将字符串文字作为参数传递。

#define T("x") "x"

That defines a macro function T , and what would be a parameter named x if there weren't any quotes. 它定义了一个宏函数T ,如果没有引号,它将是一个名为x的参数。 You could try something like this instead: 您可以尝试这样的方法:

#define T(x) #x

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM