#include
Preprocessing DirectiveAll preprocessing directives begin with #
and are processed before the program is compiled.
Only whitespace characters may appear before a preprocessing directive on a line.
The #include
directive includes a copy of the specified file. If the filename is enclosed in quotes, the preprocessor begins searching in the same directory as the file being compiled for the file to be included. If the filename is enclosed in angle brackets (<
and >
), the search is performed in an implementation-defined manner.
#define
Preprocessing Directive: Symbolic ConstantsThe #define
preprocessing directive is used to create symbolic constants and macros.
A symbolic constant is a name for a constant.
#define
Preprocessing Directive: MacrosA macro is an operation defined in a #define
preprocessing directive. Macros may be defined with or without arguments.
The replacement text for a macro or symbolic constant is any text remaining on the line after the identifier (and, if any, the macro argument list) in the #define
directive. If the replacement text for a macro or symbolic constant is too long to fit on one line, a backslash () is placed at the end of the line, indicating that the replacement text continues on the next line.
Symbolic constants and macros can be discarded using the #undef
preprocessing directive. Directive #undef
“undefines” the symbolic constant or macro name.
The scope of a symbolic constant or macro is from its definition until it is either undefined with
#undef
or the end of the file is reached.
Conditional compilation enables you to control the execution of preprocessing directives and the compilation of program code.
The conditional preprocessing directives evaluate constant integer expressions. Cast expressions, sizeof
expressions and enumeration constants cannot be evaluated in preprocessing directives.
Every #if
construct ends with #endif
.
Directives #ifdef
and #ifndef
are provided as shorthand for #if defined(
name)
and #if !defined(
name)
.
A multiple-part conditional preprocessor construct is tested with directives #elif
and #else
.
#error
and #pragma
Preprocessing DirectivesThe #error
directive prints an implementation-dependent message that includes the tokens specified in the directive and terminates preprocessing and compiling.
The #pragma
directive causes an implementation-defined action. If the pragma is not recognized by the implementation, the pragma is ignored.
#
and ##
The #
operator causes the following replacement text token to be converted to a string surrounded by quotes. The #
operator must be used in a macro with arguments, because the operand of #
must be an argument of the macro.
The ##
operator concatenates two tokens. The ##
operator must have two operands.
There are six predefined symbolic constants. Constant __LINE__
is the line number of the current source-code line (an integer). Constant __FILE__
is the presumed name of the file (a string). Constant __DATE__
is the date the source file is compiled (a string). Constant __TIME__
is the time the source file is compiled (a string). Note that each of the predefined symbolic constants begins (and, with the exception of __cplusplus
, ends) with two underscores.
The assert
macro—defined in the <cassert>
header file—tests the value of an expression. If the value of the expression is 0
(false), then assert
prints an error message and calls function abort
to terminate program execution.