cpp: If
1
1 4.2.2 If
1 --------
1
1 The '#if' directive allows you to test the value of an arithmetic
1 expression, rather than the mere existence of one macro. Its syntax is
1
1 #if EXPRESSION
1
1 CONTROLLED TEXT
1
1 #endif /* EXPRESSION */
1
1 EXPRESSION is a C expression of integer type, subject to stringent
1 restrictions. It may contain
1
1 * Integer constants.
1
1 * Character constants, which are interpreted as they would be in
1 normal code.
1
1 * Arithmetic operators for addition, subtraction, multiplication,
1 division, bitwise operations, shifts, comparisons, and logical
1 operations ('&&' and '||'). The latter two obey the usual
1 short-circuiting rules of standard C.
1
1 * Macros. All macros in the expression are expanded before actual
1 computation of the expression's value begins.
1
1 * Uses of the 'defined' operator, which lets you check whether macros
1 are defined in the middle of an '#if'.
1
1 * Identifiers that are not macros, which are all considered to be the
1 number zero. This allows you to write '#if MACRO' instead of
1 '#ifdef MACRO', if you know that MACRO, when defined, will always
1 have a nonzero value. Function-like macros used without their
1 function call parentheses are also treated as zero.
1
1 In some contexts this shortcut is undesirable. The '-Wundef'
1 option causes GCC to warn whenever it encounters an identifier
1 which is not a macro in an '#if'.
1
1 The preprocessor does not know anything about types in the language.
1 Therefore, 'sizeof' operators are not recognized in '#if', and neither
1 are 'enum' constants. They will be taken as identifiers which are not
1 macros, and replaced by zero. In the case of 'sizeof', this is likely
1 to cause the expression to be invalid.
1
1 The preprocessor calculates the value of EXPRESSION. It carries out
1 all calculations in the widest integer type known to the compiler; on
1 most machines supported by GCC this is 64 bits. This is not the same
1 rule as the compiler uses to calculate the value of a constant
1 expression, and may give different results in some cases. If the value
1 comes out to be nonzero, the '#if' succeeds and the CONTROLLED TEXT is
1 included; otherwise it is skipped.
1