包含编译时变量的#if
预处理程序阶段语句如何在预处理程序阶段自行解析?
以下代码运行时没有任何错误:
#include<stdio.h>
void main()
{
int num=10; /* compile time */
#if((num%2)==0) /* #if is preprocessor stage but has num of compile time why not error here? */
printf("\nNumber is Even");
#else
printf("\nNumber is Odd");
#endif
}
答案 0 :(得分:11)
对于#if
中的评估,预处理器会通过适当的扩展替换已定义的宏的所有标识符。之后保留的所有标识符都具有值0
。