#include<stdio.h>
int main()
{
#if HELLO
printf("%d\n",1);
#endif
}
In this code I am expecting error in the preprocessor stage because the maco HELLO is undefined. But it doesn't generate any error and simple ignore that printf statement. Why here #if directive act as #ifdef directive ?
C 2018 6.10.1 4 says that each identifier in a
#ifdirective that is not either defined as a macro or used with thedefinedoperator is replaced with0:Regarding your statement:
You should not expect that because no statement in the C standard says that should happen, nor does any reputable third-party documentation say it should happen. As you learn to program, be on guard about making assumptions about how things should behave. Learn to rely on written documentation rather than intuition.