Is it standard for #if to assume undefined symbolic constants as 0?

后端 未结 2 834
清酒与你
清酒与你 2020-12-11 15:47

In this c program

#include
int main()
{

        #if UnDefinedSymbolicConstant==0
                printf(\"UnDefinedSymbolicCon         


        
相关标签:
2条回答
  • 2020-12-11 16:08

    Yes, this is specified by the standard in 6.10.1:

    After all replacements due to macro expansion and the defined unary operator have been performed, all remaining identifiers (including those lexically identical to keywords) are replaced with the pp-number 0

    0 讨论(0)
  • 2020-12-11 16:18

    It is the default, but you might at least generate warnings for this using the -Wundef option to gcc.

    `-Wundef': Warn whenever an identifier which is not a macro is encountered in an `#if' directive, outside of `defined'. Such identifiers are replaced with zero.

    0 讨论(0)
提交回复
热议问题