#if
The preprocessor enables the conditional copying of its input. At the start, its default mode is copy, meaning that characters in the input are copied to the output. Conditional directives enable another mode: skip, by means of which the following characters are discarded, and only newline characters are copied.
Conditional directives follow the familiar syntax of some of their cousins in programming languages. At the very least,
they start with the
#if
directive, followed by a Boolean expression as argument,and they are closed by
#endif
.
It is also possible to use
one
#else
directive before#endif
;a series of
#elif
directive after#if
(as a short-hand for a#else
immediately followed by an#if
, except that only one#endif
will close the conditional).
A trivial example would be:
where false
is a predefined symbol acting like a Boolean value. The
output is
Note what looks like an anonymous preprocessing directive # 1 "Tests/test.txt"
. We will explain its meaning when presenting
The Inclusion Directive. (Remark: cpp
would not output blank lines followed by the end of the file.) Their
use is clearer if we add text before and after the conditional, like
so:
whose preprocessed output is then
Here is how to use the #else
directive: