Using the #include Directive when Compiling Source in a Data Management File
The following table indicates the search path the 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 |
Note: 1 If the include file format <file/mbr.h> is used, the compiler searches for mbr in the file in the library list first. If mbr is not found, then the compiler searches for mbr.h in the same file in the library list. Only "h" or "H" are allowed as member name extensions. |
If library and file are not specified, the preprocessor uses a specific search path depending on which delimiter surrounds the filename. The < > delimeter 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 for the C compiler, STD for the C++ compiler
- ” "
- 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 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:
/* defs.h */
#define TRUE 1
#define FALSE 0
#define BUFFERSIZE 512
#define MAX_ROW 66
#define MAX_COLUMN 80
int hour;
int min;
int sec;
#include "mydefs.h"
You can imbed 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.
#define IO_HEADER <stdio.h>
.
.
.
#include IO_HEADER /* equivalent to specifying #include <stdio.h> */
.
.
.
Beginning of C++0x only.
In C++0x, the changes to header and include file names in the C99
preprocessor are adopted to provide a common preprocessor interface
for C and C++ compilers. The first character of a header file name
in an #include
directive must not be a digit in C++0x.
For more information, see C99 preprocessor features adopted in C++11 (C++11).
End of C++0x only.