9.5 Pre-processing directives

9.5 Pre-processing directives
The pre-processing directives provide the ability to conditionally skip
sections of source files, to report error and
warning conditions, and to delineate distinct regions of source code.
[Note: The term .pre-processing directives.
is used only for consistency with the C and C++ programming languages. In
C#, there is no separate preprocessing
step; pre-processing directives are processed as part of the lexical
analysis phase. end note]
pp-directive::
pp-declaration
pp-conditional
pp-line
pp-diagnostic
pp-region
The following pre-processing directives are available:
. #define and #undef, which are used to define and undefine, respectively,
conditional compilation symbols
(§9.5.3).
. #if, #elif, #else, and #endif, which are used to conditionally skip
sections of source code (§9.5.1).
. #line, which is used to control line numbers emitted for errors and
warnings (§9.5.7).
. #error and #warning, which are used to issue errors and warnings,
respectively (§9.5.5).
. #region and #endregion, which are used to explicitly mark sections of
source code (§9.5.6).
A pre-processing directive always occupies a separate line of source code
and always begins with a # character
and a pre-processing directive name. White space may occur before the #
character and between the # character
and the directive name.
A source line containing a #define, #undef, #if, #elif, #else, #endif, or
#line directive may end with a
single-line comment. Delimited comments (the /* */ style of comments) are
not permitted on source lines
containing pre-processing directives.
Pre-processing directives are not tokens and are not part of the syntactic
grammar of C#. However, preprocessing
directives can be used to include or exclude sequences of tokens and can in
that way affect the
meaning of a C# program. [Example: For example, when compiled, the program
#define A
#undef B
class C
{
#if A
void F() {}
#else
void G() {}
#endif
Chapter 9 Lexical structure
63
#if B
void H() {}
#else
void I() {}
#endif
}
results in the exact same sequence of tokens as the program
class C
{
void F() {}
void I() {}
}
Thus, whereas lexically, the two programs are quite different,
syntactically, they are identical. end example]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值