if-endif的行为是否与scope类似?
正如标题所提示的,我的问题是预处理器指令if和endif是否起作用域的作用?考虑这个例子:if-endif的行为是否与scope类似?,c,scope,c-preprocessor,preprocessor-directive,C,Scope,C Preprocessor,Preprocessor Directive,正如标题所提示的,我的问题是预处理器指令if和endif是否起作用域的作用?考虑这个例子: #define foo 1 #define bar 1 #if foo #undef bar #endif //foo // Is 'bar' defined or undefined here? 现在,使用您的示例进行测试,您将看到: #include <stdio.h> #define foo 1 #define bar 1 #if foo #undef bar #endif /
#define foo 1
#define bar 1
#if foo
#undef bar
#endif //foo
// Is 'bar' defined or undefined here?
现在,使用您的示例进行测试,您将看到:
#include <stdio.h>
#define foo 1
#define bar 1
#if foo
#undef bar
#endif //foo
int main() {
printf("%d", bar);
return 0;
}
正如您所看到的,它是未声明的如果您指的是定义的生命周期范围,那么不,它不是范围。条形图将未定义。如何检查:如果为foo,但没有该值?请重新打开。这是一个不同的问题,而不是引用的问题的重复。无论编译器如何,都会是这种情况吗?我在理论上问。@G.Rassovsky是的,请看:
[Error] 'bar' undeclared (first use in this function)