The #if directive conditionally includes text for preprocessing. If the condition that follows the #if directive evaluates to a nonzero value, the text following up to but excluding the associated #endif is included as preprocessing input.
The #elif (a contraction of else-if) directive, if used, must be contained within a section of text subject to an #if directive. This directive optionally includes a section of text based on the evaluation result of the condition that immediately follows the directive. The #elif directive evaluates its condition only when the original condition on the #if evaluates to false and all conditions associated with preceding #elif directives subject to the original #if also evaluate to false.
#if and #elif directive syntax >>-#--+-if---+--constant_expression---------------------------->< '-elif-'
All macros are expanded, except macros that are the operand of a defined operator. Any uses of the defined operator are processed, and all remaining keywords and identifiers are replaced with the token 0 except true and false.
The behavior is undefined if expanding the macros resulted in the token defined.
#if static_cast<int>(1)
#error Unexpected
#endif
int main() {
}
defined identifier
defined(identifier)
#if defined(TEST1) || defined(TEST2)
#include <stdio.h>
int main()
{
#if TEST != 0 // No error even when TEST is not defined.
printf("Macro TEST is defined to a non-zero value.");
#endif
}