gpt4 book ai didi

c - 海湾合作委员会错误 : expected expression before 'else'

转载 作者:太空宇宙 更新时间:2023-11-04 05:19:25 31 4
gpt4 key购买 nike

我想知道为什么这样的代码在编译时会产生以下错误:

1.c:11: 错误:'else' 之前的预期表达式

代码:

#include <stdio.h> 

#define xprintk(...) while(0);


int main (void)
{
if (1)
xprintk("aaa\n");
else
xprintk("bbb\n");

return 0;
}

最佳答案

 #define xprintk(...)    while(0)
^^ Remove semi-colon

看看预处理后会发生什么

gcc -E test.c

int main (void)
{
if (1)
while(0);; //<- Two semi-colon (i.e. Two statements)
else
while(0);; //<- Two semi-colon

return 0;
}

关于c - 海湾合作委员会错误 : expected expression before 'else' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18809180/

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