www.gibmonks.com

Main Page

Previous Page
Next Page

[Page 1280 (continued)]

Summary

  • All preprocessor directives begin with # and are processed before the program is compiled.

  • Only white-space characters may appear before a preprocessor directive on a line.

  • The #include directive includes a copy of the specified file. If the file name 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 file name is enclosed in angle brackets (< and >), the search is performed in an implementation-defined manner.

  • The #define preprocessor directive is used to create symbolic constants and macros.

  • A symbolic constant is a name for a constant.

  • A macro is an operation defined in a #define preprocessor 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 preprocessor 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 the programmer to control the execution of preprocessor directives and the compilation of program code.

  • The conditional preprocessor directives evaluate constant integer expressions. Cast expressions, sizeof expressions and enumeration constants cannot be evaluated in preprocessor 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.

  • The #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.


  • [Page 1281]
  • 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 macrodefined in the <cassert> header filetests 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.


Previous Page
Next Page