15 Preprocessing directives [cpp]
preprocessing-file:
groupopt
module-file
module-file:
pp-global-module-fragmentopt pp-module groupopt pp-private-module-fragmentopt
pp-global-module-fragment:
module ; new-line groupopt
pp-private-module-fragment:
module : private ; new-line groupopt
group:
group-part
group group-part
group-part:
control-line
if-section
text-line
# conditionally-supported-directive
control-line:
# include pp-tokens new-line
pp-import
# define identifier replacement-list new-line
# define identifier lparen identifier-listopt ) replacement-list new-line
# define identifier lparen ... ) replacement-list new-line
# define identifier lparen identifier-list , ... ) replacement-list new-line
# undef identifier new-line
# line pp-tokens new-line
# error pp-tokensopt new-line
# pragma pp-tokensopt new-line
# new-line
if-section:
if-group elif-groupsopt else-groupopt endif-line
if-group:
# if constant-expression new-line groupopt
# ifdef identifier new-line groupopt
# ifndef identifier new-line groupopt
elif-groups:
elif-group
elif-groups elif-group
elif-group:
# elif constant-expression new-line groupopt
else-group:
# else new-line groupopt
endif-line:
# endif new-line
text-line:
pp-tokensopt new-line
conditionally-supported-directive:
pp-tokens new-line
lparen:
a ( character not immediately preceded by white-space
identifier-list:
identifier
identifier-list , identifier
replacement-list:
pp-tokensopt
pp-tokens:
preprocessing-token
pp-tokens preprocessing-token
new-line:
the new-line character
A
preprocessing directive consists of a sequence of preprocessing tokens
that satisfies the following constraints:
At the start of translation phase 4,
the first token in the sequence,
referred to as a
directive-introducing token,
begins with the first character in the source file
(optionally after white space containing no new-line characters) or
follows white space containing at least one new-line character,
and is
The last token in the sequence is the first token within the sequence that
is immediately followed by whitespace containing a new-line character
. [
Note: A new-line character ends the preprocessing directive even if it occurs
within what would otherwise be an invocation of a function-like macro
. —
end note ]
[
Example:
#
module ;
export module leftpad;
import <string>;
export import "squee";
import rightpad;
import :part;
module
;
export
import
foo;
export
import foo;
import ::
import ->
—
end example ]
A sequence of preprocessing tokens is only a
text-line
if it does not begin with a directive-introducing token
. When in a group that is skipped (
[cpp.cond]), the directive
syntax is relaxed to allow any sequence of preprocessing tokens to occur between
the directive name and the following new-line character
.The only white-space characters that shall appear
between preprocessing tokens
within a preprocessing directive
(from just after the directive-introducing token
through just before the terminating new-line character)
are space and horizontal-tab
(including spaces that have replaced comments
or possibly other white-space characters
in translation phase 3)
.The implementation can
process and skip sections of source files conditionally,
include other source files,
import macros from header units,
and replace macros
. These capabilities are called
preprocessing,
because conceptually they occur
before translation of the resulting translation unit
.The preprocessing tokens within a preprocessing directive
are not subject to macro expansion unless otherwise stated
.[
Example: In:
#define EMPTY
EMPTY # include <file.h>
the sequence of preprocessing tokens on the second line is
not
a preprocessing directive, because it does not begin with a
# at the start of
translation phase 4, even though it will do so after the macro
EMPTY
has been replaced
. —
end example ]