Standard C++ Library Reference ISO/IEC (VERSION3)
Preprocessing
The translator processes each source file in a series of phases. Preprocessing constitutes the
earliest phases, which produce a translation unit. Preprocessing treats a source file as a sequence
of text lines. You can specify directives and macros that insert, delete, and alter source text.
This document describes briefly just those aspects of preprocessing most relevant to the use of
the Standard C library:
The macro __FILE__ expands to a string literal that gives the remembered filename of the
current source file. You can alter the value of this macro by writing a line directive.
The macro __LINE__ expands to a decimal integer constant that gives the remembered line
number within the current source file. You can alter the value of this macro by writing a line
directive.
A define directive defines a name as a macro. Following the directive name define, you
write one of two forms:
a name not immediately followed by a left parenthesis, followed by any sequence of
preprocessing tokens -- to define a macro without parameters
●
a name immediately followed by a left parenthesis with no intervening white space,
followed by zero or more distinct parameter names separated by commas, followed by a
right parenthesis, followed by any sequence of preprocessing tokens -- to define a macro
with as many parameters as names that you write inside the parentheses
●
You can selectively skip groups of lines within source files by writing an if directive, or one of
the other conditional directives, ifdef or ifndef. You follow the conditional directive by the first
group of lines that you want to selectively skip. Zero or more elif directives follow this first
group of lines, each followed by a group of lines that you want to selectively skip. An optional
else directive follows all groups of lines controlled by elif directives, followed by the last group
of lines you want to selectively skip. The last group of lines ends with an endif directive.
At most one group of lines is retained in the translation unit -- the one immediately preceded by
a directive whose #if expression has a nonzero value. For the directive:
#ifdef X
this expression is defined (X), and for the directive:
#ifndef X
this expression is !defined (X).
A #if expression is a conditional expression that the preprocessor evaluates. You can write only
integer constant expressions, with the following additional considerations: