Alex Rivera | Logout

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

Asked 2012-07-04T13:19:42.637
14

In this c program

#include<stdio.h>
int main()
{

        #if UnDefinedSymbolicConstant==0
                printf("UnDefinedSymbolicConstant is equal to 0\n ");
        #else
                printf("UnDefinedSymbolicConstant is not equal to 0\n");

        #endif
        return 0;
}

UnDefinedSymbolicConstant has not been #define anywhere, still it is being assumed as 0 and gives the output on gcc-4.3.4 as:

UnDefinedSymbolicConstant is equal to 0

so, Is this the standard behaviour or it works like this only in gcc?

Edit
Report

1 Answer

6

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.

answered 2012-07-04T13:32:05.003

Your Answer