如何在不产生错误的情况下获取包含已解析变量的#if 预处理器条件?
How gets an #if Preprocessor conditional which contains a variable resolved without producing an error?
包含编译时变量的 #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
}
对于 #if
中的评估,预处理器通过适当的扩展替换所有已定义为宏的标识符。之后保留的所有标识符的值为 0
.
包含编译时变量的 #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
}
对于 #if
中的评估,预处理器通过适当的扩展替换所有已定义为宏的标识符。之后保留的所有标识符的值为 0
.