Preprocessor Directives - An Overview

Preprocessor directives begin with the # token followed by a preprocessor keyword. The # token must appear as the first character that is not white space on a line. The # is not part of the directive name and can be separated from the name with white spaces.

A preprocessor directive ends at the new-line character unless the last character of the line is the \ (backslash) character. If the \ character appears as the last character in the preprocessor line, the preprocessor interprets the \ and the new-line character as a continuation marker. The preprocessor deletes the \ (and the following new-line character) and splices the physical source lines into continuous logical lines.

Preprocessor directives can appear anywhere in the program.

The following preprocessor directives are supported under VisualAge C++.

#define Defines a preprocessor directive.
#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.