我尝试了一些尴尬的预处理和像这样的东西来到了:预处理器错误时=
#include <stdio.h>
#define SIX =6
int main(void)
{
int x=6;
int y=2;
if(x=SIX)
printf("X == 6\n");
if(y=SIX)
printf("Y==6\n");
return 0;
}
GCC给我的错误:
test.c: In function ‘main’:
test.c:10:8: error: expected expression before ‘=’ token
test.c:12:8: error: expected expression before ‘=’ token
这是为什么?
可能出现[您遇到过的最糟糕的真实世界宏/预处理器滥用情况?](http://stackoverflow.com/questions/652788/what-is-the-worst-real -world-macros-pre-processor-abuse-youve-ever-come-across)只是在开玩笑,好问题。 –
通过预处理器运行,测试变成'if(x = = 6)'。我不确定为什么这个空间被插入......据推测,知道C规格比我好得多的人会来... – cdhowie
预处理器处理令牌,逻辑上用空格分隔令牌。当它标记'if(x = SIX)'时,它具有'if','(','x','='和'SIX')。当它扩展'SIX'时,它有额外的标记'='和'6',但是两个相邻的标记'='与一个标记'=='不一样(实际上C语法是无效的) - 因此编译错误 –