是否在扩展宏之前处理预处理器指令?
Are preprocessor directives processed before macros are expanded?
是否在扩展宏之前处理预处理器指令?
谢谢
是也不是。每个预处理器指令都定义了自己与宏替换的交互。一般规则是 (C++11 16/6):
The preprocessing tokens within a preprocessing directive are not subject to macro expansion unless otherwise
stated.
另一个相关的一般规则是 16/1:
A preprocessing directive consists of a sequence of preprocessing tokens that satisfies the following constraints:
The first token in the sequence is a #
preprocessing token that (at the start of translation phase 4) is either
the first character in the source file (optionally after white space containing no new-line characters) or that
follows white space containing at least one new-line character. The last token in the sequence is the first newline
character that follows the first token in the sequence. A new-line character ends the preprocessing
directive even if it occurs within what would otherwise be an invocation of a function-like macro.
(翻译阶段 4 是预处理)。
个别指令的一些规则:
#if
和 #elif
在其参数中扩展宏,defined
(16.1/4).
[=39 的参数除外=]
#include
在其参数中扩展宏;它们最终必须扩展为由 ""
或 <>
.
分隔的字符串
#line
在其参数中扩展宏;它们最终必须扩展为 #line
(16.4/5)
的非宏参数的有效语法
是否在扩展宏之前处理预处理器指令?
谢谢
是也不是。每个预处理器指令都定义了自己与宏替换的交互。一般规则是 (C++11 16/6):
The preprocessing tokens within a preprocessing directive are not subject to macro expansion unless otherwise stated.
另一个相关的一般规则是 16/1:
A preprocessing directive consists of a sequence of preprocessing tokens that satisfies the following constraints: The first token in the sequence is a
#
preprocessing token that (at the start of translation phase 4) is either the first character in the source file (optionally after white space containing no new-line characters) or that follows white space containing at least one new-line character. The last token in the sequence is the first newline character that follows the first token in the sequence. A new-line character ends the preprocessing directive even if it occurs within what would otherwise be an invocation of a function-like macro.
(翻译阶段 4 是预处理)。
个别指令的一些规则:
[=39 的参数除外=]#if
和#elif
在其参数中扩展宏,defined
(16.1/4).#include
在其参数中扩展宏;它们最终必须扩展为由""
或<>
. 分隔的字符串
#line
在其参数中扩展宏;它们最终必须扩展为#line
(16.4/5) 的非宏参数的有效语法