gpt4 book ai didi

#if 0 和#endif 之间的代码块必须有成对的双引号吗?

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

int main(void)
{
#if 0
something"
#endif
return 0;
}

上面的一个简单程序会生成一个警告:missing terminating "character in gcc。这看起来很奇怪,因为这意味着编译器允许 #if 0 之间的代码块和 endif 在这里有像 something 这样的无效语句,但没有不配对的双引号 "#ifdef#ifndef 的使用也是如此。

真正的评论在这里没问题:

int main(void)
{
/*
something"
*/
return 0;
}

为什么?和单引号'的行为类似,有没有其他特殊处理的标记?

最佳答案

参见 comp.Lang.c FAQ, 11.19 :

Under ANSI C, the text inside a "turned off" #if, #ifdef, or #ifndef must still consist of "valid preprocessing tokens." This means that the characters " and ' must each be paired just as in real C code, and the pairs mustn't cross line boundaries.

关于#if 0 和#endif 之间的代码块必须有成对的双引号吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24230629/

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