Examples

#include <iostream.h> #include "myheader.h" #ifdef MINE

#define filename "file1.h" #else

#define filename "file2.h" #endif

#include filename

The #include_next preprocessor directive is similar to the #include directive, but tells the preprocessor to continue the include-file search beyond the current directory, and include the subsequent instance found in the file-search path.

Macro Replacement (#define, #undef)

You can define C++ macros to substitute text in your source file.

Syntax

macro-directive ::=

#define identifier [replacement-list]

#define identifier( [identifier-list] ) [replacement-list] #undef identifier

replacement-list ::= token replacement-list token

Description

A#define preprocessing directive defines the identifier as a macro name that represents the replacement-list. This is of the form:

#define identifier [replacement-list]

The macro name is then replaced by the list of tokens wherever it appears in the source file (except inside of a string, character constant, or comment). A macro definition remains in force until it is undefined through the use of the #undef directive or until the end of the compilation unit.

The replacement-listmust fit on one line. If the line becomes too long, it can be broken up into several lines provided that all lines but the last are terminated by a backslash (\) character. The following is an example:

#define mac very very long\

replacement string

The \ must be the last character on the line. You cannot add any spaces or comments after it.

Macros can be redefined without an intervening #undef directive. Any parameter used must agree in number and spelling with the original definition, and the replacement lists must be identical. All white space within the replacement-list is treated as a single blank space regardless of the number of white-space characters you use. For example, the following #define directives are equivalent:

#define foo x + y

#define foo x + y

The replacement-listmay be empty. If the token list is not provided, the macro name is replaced with no characters.

Macros with Parameters

You can create macros that have parameters. The syntax of the #define directive that includes formal parameters is as follows:

Overview of the Preprocessor 121