X hits on this document

1189 views

0 shares

0 downloads

0 comments

61 / 396

C# LANGUAGE SPECIFICATION

directive.

Any #define and #undef directives in a source file must occur before the first token (§‎2.4) in the source file; otherwise a compile-time error occurs. In intuitive terms, #define and #undef directives must precede any “real code” in the source file.

The example:

#define Enterprise

#if Professional || Enterprise #define Advanced #endif

namespace Megacorp.Data { #if Advanced class PivotTable {...} #endif }

is valid because the #define directives precede the first token (the namespace keyword) in the source file.

The following example results in a compile-time error because a #define follows real code:

#define A namespace N { #define B #if B class Class1 {} #endif }

A #define may define a conditional compilation symbol that is already defined, without there being any intervening #undef for that symbol. The example below defines a conditional compilation symbol A and then defines it again.

#define A #define A

A #undef may “undefine” a conditional compilation symbol that is not defined. The example below defines a conditional compilation symbol A and then undefines it twice; although the second #undef has no effect, it is still valid.

#define A #undef A #undef A

2.5.4 Conditional compilation directives

The conditional compilation directives are used to conditionally include or exclude portions of a source file.

pp-conditional: pp-if-section   pp-elif-sectionsopt   pp-else-sectionopt   pp-endif

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

pp-elif-sections: pp-elif-section pp-elif-sections   pp-elif-section

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

Document info
Document views1189
Page views1189
Page last viewedWed Jan 18 16:39:48 UTC 2017
Pages396
Paragraphs9401
Words133190

Comments