ISO/IEC 9899:202x (E) working draft — February 5, 2020 C17..C2x N2479:
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, and then each preprocessing token is converted into a token.
In other words:
An identifier that is not defined as a macro is converted to 0 before the expression is evaluated.
This leads to the fact that UNDEFINED == 0 is true:
#if UNDEFINED == 0
#pragma message "UNDEFINED == 0 is true"
#endif
$ gcc t0.c -E
t0.c:3:9: note: '#pragma message: UNDEFINED == 0 is true'
However, how conceptually (logically, mathematically, philosophically, etc.) UNDEFINED can equal to 0 (leading to UNDEFINED == 0 is true)?
For example, in IEEE 754 the NaN can be seen as UNDEFINED (Not a Number, hence, there is no number, the number is not defined, i.e. undefined) and NaN == 0 is false:
#include <stdio.h>
#include <math.h>
int main( void )
{
printf("NaN == 0 is %d\n", NAN == 0);
return 0;
}
$ gcc t0.c && ./a.exe
NaN == 0 is 0
Question: What is the motivation behind treating in C preprocessor undefined macro as 0?