[cpp.include] (original) (raw)

15 Preprocessing directives [cpp]

15.3 Source file inclusion [cpp.include]

A#includedirective shall identify a header or source file that can be processed by the implementation.

A preprocessing directive of the form

searches a sequence ofimplementation-defined places for a header identified uniquely by the specified sequence between the<and>delimiters, and causes the replacement of that directive by the entire contents of the header.

How the places are specified or the header identified is implementation-defined.

A preprocessing directive of the form

causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the"delimiters.

The named source file is searched for in animplementation-defined manner.

If this search is not supported, or if the search fails, the directive is reprocessed as if it read

with the identical contained sequence (including>characters, if any) from the original directive.

A preprocessing directive of the form

(that does not match one of the two previous forms) is permitted.

The preprocessing tokens afterincludein the directive are processed just as in normal text (i.e., each identifier currently defined as a macro name is replaced by its replacement list of preprocessing tokens).

If the directive resulting after all replacements does not match one of the two previous forms, the behavior is undefined.

The method by which a sequence of preprocessing tokens between a<and a>preprocessing token pair or a pair of"characters is combined into a single header name preprocessing token is implementation-defined.

The implementation shall provide unique mappings for sequences consisting of one or morenondigits or digits ([lex.name]) followed by a period (.) and a singlenondigit.

The first character shall not be a digit.

The implementation may ignore distinctions of alphabetical case.

A#includepreprocessing directive may appear in a source file that has been read because of a#includedirective in another file, up to an implementation-defined nesting limit.

If the header identified by the denotes an importable header ([module.import]), it isimplementation-defined whether the #include preprocessing directive is instead replaced by an import directive ([cpp.import]) of the form

[Note 2:

An implementation can provide a mechanism for making arbitrary source files available to the < > search.

However, using the < > form for headers provided with the implementation and the " " form for sources outside the control of the implementation achieves wider portability.

For instance:#include <stdio.h> #include <unistd.h> #include "usefullib.h" #include "myprog.h"

— _end note_]

[Example 1:

This illustrates macro-replaced#includedirectives:#if VERSION == 1 #define INCFILE "vers1.h" #elif VERSION == 2 #define INCFILE "vers2.h" #else #define INCFILE "versN.h" #endif #include INCFILE

— _end example_]