A preprocessor include directive causes the preprocessor to replace the directive with the contents of the specified file. The include directive has the form:
>>-#include--+-<filename>-+------------------------------------>< '-"filename"-'
The following table indicates the search path compiler takes for source
physical files. See the default file names and search paths
below.
Filename | Member | File | Library |
---|---|---|---|
mbr | mbr | default file | default search |
file/mbr1 | mbr | file | default search |
mbr.file | mbr | file | default search |
lib/file/mbr | mbr | file | lib |
lib/file(mbr) | mbr | file | lib |
|
If library and file are not specified, the preprocessor uses a specific search path depending on which delimiter surrounds the filename. The < > delimiter specifies the name as a system include file. The " " delimiter specifies the name as a user include file.
The following describes the search paths for the #include directive used by the compiler.
- Default File Names When the Library and File are not Named (member name only):
- Include Type
- Default File Name
- < >
- QCSRC
- " "
- The source file of the root source member, where root source member is the library, file, and member determined by the SRCFILE option of the Create Module or Create Bound Program commands.
- Default Search Paths When the Filename is not Library Qualified:
- Include Type
- Search Path
- < >
- Searches the current library list (*LIBL)
- " "
- Checks the library containing the root source member; if not found there, the compiler searches the user portion of the library list, using either the filename specified or the file name of the root source member (if no filename is specified); if not found, the compiler searches the library list (*LIBL) using the specified filename.
- Search Paths When the Filename is Library Qualified (lib/file/mbr):
- Include Type
- Search Path
- < >
- Searches for lib/file/mbr only
- " "
- Searches for the member in the library and file named. If not found, searches the user portion of the library list, using the file and member names specified.
User includes are treated the same as system includes when the *SYSINCPATH option has been specified with the Create Module or Create Bound Program commands.
The preprocessor resolves macros on a #include directive. After macro replacement, the resulting token sequence must consist of a file name enclosed in either double quotation marks or the characters < and >. For example:
#define MONTH <july.h> #include MONTH
Usage
If there are a number of declarations used by several files, you can place all these definitions in one file and #include that file in each file that uses the definitions. For example, the following file defs.h contains several definitions and an inclusion of an additional file of declarations:
|
You can embed the definitions that appear in defs.h with the following directive:
#include "defs.h"
One of the ways you can combine the use of preprocessor directives is demonstrated in the following example. A #define is used to define a macro that represents the name of the C or C++ standard I/O header file. A #include is then used to make the header file available to the C or C++ program.
|
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.