Preprocessor Overview

Preprocessing is a preliminary operation on C and C++ files before they are passed to the compiler. It allows you to do the following:

A token is a series of characters delimited by white space. The only white space allowed on a preprocessor directive is the space, horizontal tab, vertical tab, form feed, and comments. The new-line character can also separate preprocessor tokens.

The preprocessed source program file must be a valid C or C++ program.

The preprocessor is controlled by the following directives:

#define
Defines a macro.
#undef
Removes a preprocessor macro definition.
#error
Defines text for a compile-time error message.
#include
Inserts text from another source file.
#if
Conditionally suppresses portions of source code, depending on the result of a constant expression.
#ifdef
Conditionally includes source text if a macro name is defined.
#ifndef
Conditionally includes source text if a macro name is not defined.
#else
Conditionally includes source text if the previous #if, #ifdef, #ifndef, or #elif test fails.
#elif
Conditionally includes source text if the previous #if, #ifdef, #ifndef, or #elif test fails, depending on the value of a constant expression.
#endif
Ends conditional text.
#line
Supplies a line number for compiler messages.
#pragma
Specifies implementation-defined instructions to the compiler.

Related References

IBM Copyright 2003