Preprocessor
The preprocessor is executed at translation phase 4, before the compilation. The result of preprocessing is a single file which is then passed to the actual compiler.
Directives
Section titled “Directives”The preprocessing directives control the behavior of the preprocessor. Each directive occupies one line and has the following format:
- the
#character. - a sequence of:
- a standard-defined directive name (listed below) followed by the corresponding arguments, or
- one or more preprocessing tokens where the beginning token is not a standard-defined directive name, in this case the directive is conditionally-supported with implementation-defined semantics (e.g. a common extension is the directive
#warningwhich emits a user-defined message during compilation) , or - nothing, in this case the directive has no effect.
- a line break.
Preprocessing directives must not come from macro expansion.
#define EMPTYEMPTY # include <file.h> // not a preprocessing directiveCapabilities
Section titled “Capabilities”The preprocessor has the source file translation capabilities:
- conditionally compile parts of source file (controlled by directive
#if,#ifdef,#ifndef,#else,#elif,#elifdef,#elifndef, and#endif). - replace text macros while possibly concatenating or quoting identifiers (controlled by directives
#defineand#undef, and operators#and##). - include other files (controlled by directive
#includeand checked with__has_include). - cause an error or warning (controlled by directive
#erroror#warningrespectively ).
The following aspects of the preprocessor can be controlled:
- implementation-defined behavior (controlled by directive
#pragmaand operator_Pragma). In addition, some compilers support (to varying degrees) the operator__pragmaas an extension. - file name and line information available to the preprocessor (controlled by directive
#line).
Defect reports
Section titled “Defect reports”The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
CWG 2001 (C++98)
| Link | https://cplusplus.github.io/CWG/issues/2001.html |
|---|---|
| Applied to | C++98 |
| Behavior as published | the behavior of using non-standard-defined directives was not clear |
| Correct behavior | made conditionally-supported |
See also
Section titled “See also”C++ documentation for Predefined Macro Symbols
C++ documentation for Macro Symbol Index
C documentation for preprocessor