X hits on this document





64 / 396

Chapter ‎18   Unsafe code

#if X /* #else /* */ class Q { } #endif

always produces the same token stream (class Q { }), regardless of whether or not X is defined. If X is defined, the only processed directives are #if and #endif, due to the multi-line comment. If X is undefined, then three directives (#if, #else, #endif) are part of the directive set.

2.5.5 Diagnostic directives

The diagnostic directives are used to explicitly generate error and warning messages that are reported in the same way as other compile-time errors and warnings.

pp-diagnostic: whitespaceopt   #   whitespaceopt   error   pp-message whitespaceopt   #   whitespaceopt   warning   pp-message

pp-message: new-line whitespace   input-charactersopt   new-line

The example:

#warning Code review needed before check-in

#if Debug && Retail #error A build can't be both debug and retail #endif

class Test {...}

always produces a warning (“Code review needed before check-in”), and produces a compile-time error (“A build can’t be both debug and retail”) if the conditional symbols Debug and Retail are both defined. Note that a pp-message can contain arbitrary text; specifically, it need not contain well-formed tokens, as shown by the single quote in the word can’t.

2.5.6 Region directives

The region directives are used to explicitly mark regions of source code.

pp-region: pp-start-region   conditional-sectionopt   pp-end-region

pp-start-region: whitespaceopt   #   whitespaceopt   region   pp-message

pp-end-region: whitespaceopt   #   whitespaceopt   endregion   pp-message

No semantic meaning is attached to a region; regions are intended for use by the programmer or by automated tools to mark a section of source code. The message specified in a #region or #endregion directive likewise has no semantic meaning; it merely serves to identify the region. Matching #region and #endregion directives may have different pp-messages.

The lexical processing of a region:

#region ... #endregion

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

Document info
Document views683
Page views683
Page last viewedThu Oct 27 17:37:02 UTC 2016