Preprocessor directives
The preprocessor is a program that is invoked by the compiler to
process code before compilation. Commands for that program, known
as directives, are lines of the source file beginning with
the character #, which distinguishes them from lines
of source program text. The effect of each preprocessor directive
is a change to the text of the source code, and the result is a new
source code file, which does not contain the directives. The preprocessed
source code, an intermediate file, must be a valid C or C++ program,
because it becomes the input to the compiler.
- Macro definition directives, which replace tokens in the current file with specified replacement tokens
- File inclusion directives, which imbed files within the current file
- Conditional compilation directives, which conditionally compile sections of the current file
- Message generation directives, which control the generation of diagnostic messages
Assertion directives, which specify
attributes of the system the program is to run on- The null directive (#), which performs no action
- Pragma directives, which apply compiler-specific rules to specified sections of code
Preprocessor directives begin with the # token
followed by a preprocessor keyword. The # token must
appear as the first character that is not white space on a line. The # is
not part of the directive name and can be separated from the name
with white spaces.
A preprocessor directive ends at the new-line character
unless the last character of the line is the \ (backslash)
character. If the \ character appears as the last
character in the preprocessor line, the preprocessor interprets the \ and
the new-line character as a continuation marker. The preprocessor
deletes the \ (and the following new-line character)
and splices the physical source lines into continuous logical lines. White
space is allowed between backslash and the end of line character or
the physical end of record. However, this white space is usually not
visible during editing.
Except for some #pragma directives, preprocessor
directives can appear anywhere in a program.