HP 3000 Manuals

Source File Inclusion [ HP C/iX Reference Manual ] MPE/iX 5.0 Documentation


HP C/iX Reference Manual

Source File Inclusion 

You can include the contents of other files within the source file using
the #include directive.

Syntax 

     include-directive ::=
         #include <filename>
         #include "filename"
         #include identifier 

Description 

The #include preprocessor directive enables you to insert the contents of
the specified external file into the source file prior to compilation.
The file name in the #include directive may be enclosed in angle brackets
(< >) or double quotation marks (" ").  File names enclosed in angle
brackets are assumed to be standard include files that are provided with
the HP C/iX compiler.  All standard include files reside in the H group
of the SYS account.

The arguments to the #include directive are subject to macro replacement
before the directive processes them.  In the third form above, identifier 
must be in the form of one of the first two choices after macro
replacement by the preprocessor.

For example:

     #define varname "my_file"
     #include varname

Error messages produced by the compiler usually supply the file name
where the error occurred as well as the file relative line number of the
error.

The HP C/iX preprocessing phase allows for the use of non-standard
(UNIX(1) -like root names) file names in certain #include directives.
This minimizes the required source code changes when transporting code
between different systems.


FOOTNOTE (1) UNIX is a trademark of AT and T in the U.S. and other countries.
The preprocessor strips include file names enclosed in angle brackets of all prefixes and suffixes. The preprocessor then searches for a file with the resulting name in the H group of the SYS account. If the file is not found, an error is issued. For example, if you specify the following directive: #include <stdio.h> the preprocessor searches for STDIO.H.SYS. If you specify: #include <sys/errno.h> the preprocessor strips the sys/ prefix and searches for ERRNO.H.SYS. Examples #include <stdio.h> #include "myheader" #ifdef MINE # define filename "file1" #else # define filename "file2" #endif #include filename [REV BEG] Preprocessor Search of Include Files in Quotation Marks The preprocessor searches for include files enclosed in double quotation marks, (for example #include "myfile"), as follows: 1. If the include filename contains an MPE/iX group and account name, then the preprocessor searches the specified group and account. If no group and account is specified, it searches the group and account where the source file resides. If filename is not found, the preprocessor performs step 2. 2. The preprocessor removes any extensions and adds the H group to filename. It then searches the H group of the account where the source file resides. If the preprocessor does not find filename, it performs step 3.[REV END][REV BEG] 3. The preprocessor adds the SYS account to filename.H and searches for filename.H.SYS. 4. If the filename is still not found, the preprocessor issues an error. Examples #include "MYFILE" The preprocessor starts by looking for MYFILE in the group and account where the source file is located. It then looks for MYFILE.H in the account where the source file is located, and finally looks for MYFILE.H.SYS. #include "MYFILE.X" Assuming the source file is located in SRCGROUP.SRCACCT, the preprocessor looks for the include file in the following order: 1. "MYFILE.X.SRCACCT" 2. "MYFILE.SRCGROUP.SRCACCT" 3. "MYFILE.H.SRCACCT" 4. "MYFILE.H.SYS" [REV END][REV BEG] Include Files Within Include Files Files that are included can also use the #include directive. The compiler supports up to 35 levels of nested include files. Note that this search path is based on the group and account where the source file is located and not where the include file is "included". To illustrate, assuming that a program MAIN.SRCGROUP.SRCACCT contains the following directive: #include "HEADER1.X.Y" and "HEADER1.X.Y" contains another include directive: #include "HEADER2" The preprocessor looks for HEADER2.SRCGROUP.SRCACCT even though the file that includes it is in X.Y. The above searching algorithm can be modified in 2 ways; by using file equations or by using the -I option. Since include files are always fully[REV END] [REV BEG] qualified before searching by the preprocessor, a fully qualified file name must be used in a file equation to be effective. Example :file MYFILE.SRCGROUP.SRCACCT=HEADER.X.Y #include "MYFILE" This directs the preprocessor to look for HEADER.X.Y instead of MYFILE.SRCGROUP.SRCACCT.[REV END] -I Compiler Option You can alter the search algorithm used for locating included files by specifying the -I compiler option in the following format: -Igroup[.account] You use this option to specify a group and optionally an account where the preprocessor searches for included files before searching the source file's H group and the H group of the SYS account. If you omit the account specification, the account of the current user is used. Note that this is the only case where the user's account is used when searching for the include files. You can cause the preprocessor to search more than one group (and account) for included files by specifying more than one -I option. -I options are scanned left to right. If the included file is enclosed in angle brackets, the preprocessor strips the name of non-standard prefixes and suffixes and then searches the groups and accounts in the -I option(s) for the file. If the file is not found, the H group of the SYS account is searched. If the included file name is enclosed in double quotation marks, the preprocessor first searches for that file without changing the file name. It then strips the file name of prefixes and suffixes and searches in the group and the account of the source file. If the file is not found, the groups and accounts, if any, specified in the -I option(s) are searched. Then, the H group of the source file is searched. If the file is still not found, the H group of the SYS account is searched last. In summary, the preprocessor searches for names of included files enclosed in angle brackets only in the groups or accounts specified in any -I options, then in the H group of the SYS account, but never searches the group and account in which the source file is located. When the name is enclosed in double quotation marks, the group and account in which the source file is located is searched. If you use the -I compiler option, the indicated groups and accounts are searched before the H and H.SYS groups and accounts are searched, regardless of which characters surround the name. Example If you are compiling a local file TESTFILE in GRP1.ACCT1 that includes the preprocessor directive: #include "MYHEADER" and you want it to include the file MYHEADER in HOMEGRP.HOMEACCT, use the command: CCXL TESTFILE;INFO="-IHOMEGRP.HOMEACCT"


MPE/iX 5.0 Documentation