gpt4 book ai didi

c - 定义 = 时预处理器错误

转载 作者:太空狗 更新时间:2023-10-29 16:37:45 25 4
gpt4 key购买 nike

我正在尝试一些笨拙的预处理并想出了这样的东西:

#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

这是为什么?

最佳答案

==是一个单独的token,不能一分为二。你应该在你的代码上运行 gcc -E

来自 GCC 手册页:

-E Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocessed source code, which is sent to the standard output.

Input files that don't require preprocessing are ignored.

对于您的代码,gcc -E 给出以下输出

  if(x= =6)
printf("X == 6\n");

if(y= =6)
printf("Y==6\n");

第二个 = 是导致错误消息的原因 expected expression before ‘=’ token

关于c - 定义 = 时预处理器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18407072/

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