The C preprocessor manipulates the content of a source file as the first phase of compilation. The preprocessor does not parse the source text, but it does break it up into tokens for the purpose of locating macro calls. Although the compiler ordinarily invokes the preprocessor in its first pass, the preprocessor can also be invoked separately to process text without compiling.
Preprocessor directives are typically used to facilitate portability and improve program structure. Directives in the source file tell the preprocessor to perform
specific actions. For example, the preprocessor can replace tokens in the text, insert the contents of other files into the source file, or suppress compilation of part of the file by removing sections of text. Preprocessor statements are recognized and carried out before macro expansion.
Preprocessor statements use the same character set as source file statements with the exception that escape sequences are not supported. (See “Character Constants” for information on the execution character set.)
The C preprocessor recognizes the following directives:
#define#if#line#elif#ifdef#undef#else#error#ifndef#endif#include#pragma
The number sign (#) must be the first nonwhite-space character on the line containing the directive; white-space characters can appear between the number sign and the first letter of the directive. Some directives include arguments or values. Any text that follows a directive (except an argument or value that is part of the directive) must be enclosed in comment delimiters (/* */) or be preceded by two consecutive forward slashes (//). Lines containing preprocessor directives can be continued by preceding the end-of-the-line marker with a backslash (\).
Preprocessor directives can appear anywhere in a source file, but they apply only to the remainder of the source file.