Question:
In C/C , what is the assumed value for undefined constants when used in preprocessor #if conditions? Can this assumption be relied upon, or could undefined constants yield unpredictable behavior?
Answer:
According to the C99 standard, undefined constants are indeed assumed to have a value of 0 for evaluating #if conditions. This is explicitly stated in §6.10.1 ¶3:
"After all replacements due to macro expansion and the defined unary operator have been performed, all remaining identifiers are replaced with the pp-number 0."
Similarly, the C standard (§16.1 ¶4) states:
"After all replacements due to macro expansion and the defined unary operator have been performed, all remaining identifiers and keywords, except for true and false, are replaced with the pp-number 0."
Therefore, you can reliably assume that undefined constants will be treated as 0 in preprocessor #if conditions.
The above is the detailed content of Undefined Constants in Preprocessor #if Conditions: Defined or Undefined Results?. For more information, please follow other related articles on the PHP Chinese website!