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.

Table 24. Search Path Compiler for Source Physical Files
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.

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>  */
      .
      .
      .


[ Top of Page | Previous Page | Next Page | Contents | Index ]