6.10 Preprocessing directives

Previous Table of Contents "New C Standard" commentary



group: group-part group group-part

group-part: if-section control-line text-line # non-directive 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

control-line: # include pp-tokens new-line # 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

text-line: pp-tokensopt new-line

non-directive: pp-tokens new-line

lparen: a ( character not immediately preceded by white-space

replacement-list: pp-tokensopt

pp-tokens: preprocessing-token pp-tokens preprocessing-token

new-line: the new-line character

1855 A preprocessing directive preprocessing directive consists of a sequence of preprocessing tokens that begins with satisfies the following constraints:

1856 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 , .

1857 and is ended by the next The last token in the sequence is the first new-line character that follows the first token in the sequence. 140)

1858 A new-line character ends the preprocessing directive even if it occurs within what would otherwise be an invocation of a function-like macro.

1859 140) Thus, preprocessing directives are commonly called “lines”.

1860 These “lines” have no other syntactic significance, as all white space is equivalent except in certain situations during preprocessing (see the # character string literal creation operator in, for example).

1861 A text line shall not begin with a # preprocessing token.

1862 A non-directive shall not begin with any of the directive names appearing in the syntax.

1863 When in a group that is skipped (6.10.1), the directive syntax is relaxed to allow any sequence of preprocessing tokens to occur between the directive name and the following new-line character.

1864 The only white-space characters that shall appear between preprocessing tokens within a preprocessing directive (from just after the introducing # preprocessing 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).

1865 The implementation can process and skip sections of source files conditionally, include other source files, and replace macros.

1866 These capabilities are called preprocessing, because conceptually they occur before translation of the resulting translation unit.

1867 The preprocessing tokens within a preprocessing directive are not subject to macro expansion unless otherwise stated.

1868 EXAMPLE In:

        #define EMPTY
        EMPTY # include 

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.


Created at: 2008-01-30 02:39:44 The text from WG14/N1256 is copyright © ISO