我看到这样的结构:
#ifdef FOO || defined BAR
...
#endif
和编译器的提示“警告:#ifdef 指令末尾的额外标记”,显然应该是:
#if defined FOO || defined BAR
...
#endif
标准有明确规定吗?你能指出相关部分吗?
最佳答案
在 C99 中,6.10 预处理指令,第 1 段是语法:
if-group:
# if constant-expression new-line groupopt
# ifdef identifier new-line groupopt
# ifndef identifier new-line groupopt
这表明您使用 #ifdef
的第一个构造是不正确的,因为只有标识符可以跟在 #ifdef
之后,不允许使用常量表达式。
关于c - #ifdef 需要查询和说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9314832/