Preprocessing is a preliminary operation on C and C++ files before
they are passed to the compiler. It allows you to do the
following:
- Replace tokens in the current file with specified replacement tokens
- Imbed files within the current file
- Conditionally compile sections of the current file
- Generate diagnostic messages
- Change the line number of the next line of source and change the file name
of the current file
- Apply machine-specific rules to specified sections of code
A token is a series of characters delimited by white
space. The only white space allowed on a preprocessor directive is the
space, horizontal tab, vertical tab, form feed, and comments. The
new-line character can also separate preprocessor tokens.
The preprocessed source program file must be a valid C or C++
program.
The preprocessor is controlled by the following directives:
- #define
- Defines a macro.
- #undef
- Removes a preprocessor macro definition.
- #error
- Defines text for a compile-time error message.
- #include
- Inserts text from another source file.
- #if
- Conditionally suppresses portions of source code, depending on the result
of a constant expression.
- #ifdef
- Conditionally includes source text if a macro name is defined.
- #ifndef
- Conditionally includes source text if a macro name is not defined.
- #else
- Conditionally includes source text if the previous #if,
#ifdef, #ifndef, or #elif
test fails.
- #elif
- Conditionally includes source text if the previous #if,
#ifdef, #ifndef, or #elif
test fails, depending on the value of a constant expression.
- #endif
- Ends conditional text.
- #line
- Supplies a line number for compiler messages.
- #pragma
- Specifies implementation-defined instructions to the compiler.
Related References
