Home > Backend Development > C++ > body text

Undefined Constants in Preprocessor #if Conditions: Defined or Undefined Results?

Linda Hamilton
Release: 2024-11-10 13:25:02
Original
443 people have browsed it

Undefined Constants in Preprocessor #if Conditions: Defined or Undefined Results?

Undefined Constants in Preprocessor #if Conditions: Defined or Undefined Results?

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template