Preprocessor Directives

The preprocessor is a program that is invoked by the compiler to process code before compilation. Commands for that program, known as directives, are lines of the source file beginning with the character #, which distinguishes them from lines of source program text. The effect of each preprocessor directive is a change to the text of the source code, and the result is a new source code file, which does not contain the directives. The preprocessed source code, an intermediate file, must be a valid C or C++ program, because it becomes the input to the compiler.

The syntax of preprocessor directives is independent of, but similar to, the syntax of the rest of the language, and the lexical conventions of the preprocessor differ from those of the compiler. The preprocessor recognizes the normal C and C++ tokens, as well as other characters that enable the preprocessor to recognize file names, the presence and absence of white space, and the location of end-of-line markers.

Preprocessor directives and the related subject of macro expansion are discussed in this section. After an overview of preprocessor directives, the topics covered include textual macros, file inclusion, ISO standard and predefined macro names, conditional compilation directives, and pragmas.

Related References

IBM Copyright 2003