X hits on this document





62 / 396

Chapter ‎18   Unsafe code

pp-elif-section: whitespaceopt   #   whitespaceopt   elif   whitespace   pp-expression   pp-new-line   conditional-sectionopt

pp-else-section: whitespaceopt   #   whitespaceopt   else   pp-new-line   conditional-sectionopt

pp-endif: whitespaceopt   #   whitespaceopt   endif   pp-new-line

conditional-section: input-section skipped-section

skipped-section: skipped-section-part skipped-section   skipped-section-part

skipped-section-part: skipped-charactersopt   new-line pp-directive

skipped-characters: whitespaceopt   not-number-sign   input-charactersopt

not-number-sign: Any input-character except #

As indicated by the syntax, conditional compilation directives must be written as sets consisting of, in order, an #if directive, zero or more #elif directives, zero or one #else directive, and an #endif directive. Between the directives are conditional sections of source code. Each section is controlled by the immediately preceding directive. A conditional section may itself contain nested conditional compilation directives provided these directives form complete sets.

A pp-conditional selects at most one of the contained conditional-sections for normal lexical processing:

The pp-expressions of the #if and #elif directives are evaluated in order until one yields true. If an expression yields true, the conditional-section of the corresponding directive is selected.

If all pp-expressions yield false, and if an #else directive is present, the conditional-section of the #else directive is selected.

Otherwise, no conditional-section is selected.

The selected conditional-section, if any, is processed as a normal input-section: the source code contained in the section must adhere to the lexical grammar; tokens are generated from the source code in the section; and pre-processing directives in the section have the prescribed effects.

The remaining conditional-sections, if any, are processed as skipped-sections: except for pre-processing directives, the source code in the section need not adhere to the lexical grammar; no tokens are generated from the source code in the section; and pre-processing directives in the section must be lexically correct but are not otherwise processed. Within a conditional-section that is being processed as a skipped-section, any nested conditional-sections (contained in nested #if...#endif and #region...#endregion constructs) are also processed as skipped-sections.

The following example illustrates how conditional compilation directives can nest:

#define Debug// Debugging on #undef Trace// Tracing off

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.49

Document info
Document views1384
Page views1384
Page last viewedSun Jan 22 20:28:52 UTC 2017