|
|
HP C
|
Previous | Contents | Index |
If necessary, HP C creates the following program sections:
All program sections created by HP C have the PIC, REL, RD, USR, and NOVEC attributes. On VAX systems, the $CODE psect is aligned on a byte boundary; all other psects generated by HP C are aligned on longword boundaries. On OpenVMS Alpha and I64 systems, all psects generated by HP C are aligned on octaword boundaries. Note that use of the _align storage-class modifier can cause a psect to be aligned on greater than a longword boundary on OpenVMS VAX systems. The $CHAR_STRING_CONSTANTS psect has the same attributes as the $DATA (VAX ONLY) and $DATA$ (ALPHA, I64) psects.
Tables 4-4, 4-5, 4-6, and 4-7 summarize the differences in psects created by different declarations:
Table 4-7 shows the psect name and psect attributes for the storage-class code numbers from Table 4-4, Table 4-5, and Table 4-6. Where name is used for the psect name in Table 4-7, the name of the psect is the same as name in the declarations or pragmas in Table 4-4, or the quoted brace-enclosed names in Tables 4-5 and 4-6.
The combined use of the readonly and noshare modifiers is ignored by the compiler in the following declarations:
readonly noshare static int x; readonly noshare globaldef int x; |
When it encounters a situation as shown in the previous example, the compiler ignores the noshare modifier and accepts readonly. The order of the storage-class specifier, the storage-class modifier, and the data-type keyword within a declaration is not significant.
The HP C compiler does static (global) initialization of pointers by using the .ADDRESS directive. By using this mechanism, the compiler efficiently generates position-independent code. The linker makes image sections that contain such initialization nonshareable.
The HP C preprocessor provides the ability to perform macro substitution, conditional compilation, and inclusion of named files. Preprocessor directives, lines beginning with # and possibly preceded by white space, are used to communicate with the preprocessor. The HP C Language Reference Manual describes the standard-conforming preprocessor directives available with the HP C compiler. This chapter describes the preprocessor directives that are either specific to HP C on OpenVMS systems, or that are used in an implementation-specific way:
If you plan to port programs to and from other C implementations, take care in choosing which preprocessor directives to use within your programs. See the HP C Language Reference Manual for more information about using preprocessor directives for conditional compilation. For a complete discussion of portability concerns, see the HP C Run-Time Library Reference Manual for OpenVMS Systems.
Preprocessor directives are independent of the usual scope rules; they remain in effect from their occurrence until the end of the compilation unit. For more information about the compilation unit, see Chapter 1.
The #dictionary directive is retained for compatibility with VAX C, and is supported only when running HP C in VAX C mode (/STANDARD=VAXC). See Section 5.4.3 for information on using the standard C equivalent #pragma dictionary directive.
The #include directive inserts external text into the source stream delivered to the compiler. This directive is often used to include global definitions for use with HP C functions and macros in the program text.
The #include directive is supported on all HP C implementations, but the syntax and semantics vary. For example, the directory search algorithm for locating included files on OpenVMS systems differs from that on Tru64 UNIX systems, primarily because of differences in the native file systems and conventions on the two platforms. Nevertheless, by choosing the lowest common denominator of plain text files in directories to contain header files, you can define command-line options for both platforms to cause searching to be done in the same way. HP C for OpenVMS Systems also provides a form of the #include directive specifically for including text modules from OpenVMS text library files. The following sections describe the #include directive as implemented on OpenVMS systems.
The #include directives may be nested to a depth determined by the FILLM process quota and by virtual memory restrictions. The HP C compiler imposes no inherent limitation on the nesting level of inclusion.
OpenVMS and most UNIX style file specifications can be included in HP C source programs.
The following sections describe the different forms of the #include directive.
The first form of the #include preprocessor directive uses angle brackets (<>) to delimit the file specification:
#include <file-spec> |
The file-spec is a valid file specification or a logical name. A file specification may be up to 255 characters long.
If the file-spec contains "/" or "!" characters, it is assumed to be a UNIX style name, and the compiler attempts to combine it with other UNIX style names from the /INCLUDE_DIRECTORY command-line qualifier and translate the result to an OpenVMS file specification using RTL functions. Otherwise, the file-spec is treated as an OpenVMS file specification with defaults supplied from command-line qualifiers and logical names in a prescribed search order.
When specifying the names of files to be included in your source program, avoid directory specifications of the following form:
DBA0:[.dir-name...] |
Depending on device logical names is not good practice. Instead, try to use only simple file names complete with the .h file type, and use the /INCLUDE_DIRECTORY qualifier to specify the directories to search.
For the angle-bracket form of inclusion, the compiler searches directories in the following order for the file to be included:
You can define DECC$SYSTEM_INCLUDE to be a valid directory specification or a search list of valid directory specifications. Before each compilation of your program, you can redefine DECC$SYSTEM_INCLUDE to be any valid directory or list of directories you choose.
Avoid defining DECC$SYSTEM_INCLUDE to be a rooted directory or subdirectory of the following form:
DBA0:[dir-name.] |
When defining DECC$SYSTEM_INCLUDE, use complete directory specifications.
If DECC$SYSTEM_INCLUDE translates to a directory or a search list of directories, and if the compiler cannot locate the specified file, the compiler generates an error message. If DECC$SYSTEM_INCLUDE is undefined, the compiler then searches the DECC$LIBRARY_INCLUDE or SYS$LIBRARY directory for the specified file; if the file cannot be found, the compiler generates an error message. For more information about search lists, see the DCL command DEFINE in the HP OpenVMS DCL Dictionary.
When porting programs to the OpenVMS environment, your programs may contain #include directives of the following form:
#include <sys/file.h> |
The HP C compiler translates this line, common in programs that run on UNIX systems, to the following UNIX style file specification:
/sys/file.h |
The compiler then translates the UNIX style file specification to the OpenVMS file specification as follows:
SYS:FILE.H |
If you port programs containing such directives, define the SYS logical to be the proper name of the OpenVMS directory containing the files to be included.
Another way to use UNIX style directories is to specify them on the /INCLUDE_DIRECTORY command-line qualifier. They must contain a "/" character and must, therefore, be in quotation marks.
Previous | Next | Contents | Index |
|