HP C/HP-UX Online Help

Return to the Main HP C Online Help page



Compiling & Running HP C Programs

This section describes how to compile and run HP C programs on HP 9000 systems. The compiler command and its options are presented. You can compile HP C programs to assembly, object, or executable files. You can also optionally optimize code to improve application run-time speed.

NOTE: See the Optimizing HP C Programs section of the HP C Online help for a more detailed description of HP compiler optimization options. See the, Parallel Options & Pragmas section of HP C Online Help for detailed description of options and pragmas for threads and parallel programming.

Compiling for Different Versions of the PA-RISC Architecture
Pragmas
Gather/Scatter Prefetch
Running HP C Programs

Compiling HP C Programs

This section describes the following aspects of compiling an HP C program: When you compile a program, it passes through one or more of the following steps depending upon which command line options you use:

Compatibility Mode vs. ANSI C Mode

The HP C compiler provides two modes of operation: compatibility mode and ANSI C mode. The compatibility mode option causes the compiler to compile code in a manner similar to version 3.1. ANSI C mode is a strict implementation of the standard. See HP C Compiler Options for more information.

The cc(1) Command

Use the cc(1) command to compile HP C programs. It has the following format:

cc [options] files

where:

Specifying Files to the cc Command

Files with names ending in .c are assumed to be HP C source files. Each HP C source file is compiled, producing an object file with the same name as the source file except that the .c extension is changed to a .o extension. However, if you compile and link a single source file into an HP C program in one step, the .o file is automatically deleted.

Files with names ending in .i are assumed to be preprocessor output files (see the -P compiler option in Table 5: HP C Compiler Option Details in This section). Files ending in .i are processed the same as .c files, except that the preprocessor is not run on the .i file before the file is compiled.

Files with names ending in .s are assumed to be assembly source files; the compiler invokes the assembler to produce .o files from these.

Files with .o extensions are assumed to be relocatable object files that are included in the linking. All other files are passed directly to the linker by the compiler.

Specifying Options to the cc Command

Each compiler option has the following format:
     -optionname [optionarg]
where: The optional argument -- delimits the end of options. Any following arguments are treated as operands (typically input filenames) even if they begin with the minus (-) character.

An Example of Using a Compiler Option

By default, the cc command names the executable file a.out. For example, given the following command line:
cc demo.c
the executable file is named a.out.

You can use the -o option to override the default name of the executable file produced by cc. For example, suppose my_source.c contains C source code and you want to create an executable file name my_executable. Then you would use the following command line:

cc -o my_executable my_source.c

Concatenating Options

You can concatenate some options to the cc command under a single prefix. The longest substring that matches an option is used. Only the last option can take an argument. You can concatenate option arguments with their options if the resulting string does not match a longer option.

For example, suppose you want to compile my_file.c using the -v, -g, and -DPROG=sub compiler options. There are several ways to do this:

cc my_file.c -v -g -DPROG=sub
cc my_file.c -vg -D PROG=sub
cc my_file.c -vgDPROG=sub
cc -vgDPROG=sub my_file.c

Trigraph Sequences

The C source code character set is a superset of the ISO 646-1983 Invariant Code Set. To enable programs to be represented in the reduced set, trigraph sequences are defined to represent those characters not in the reduced set. A trigraph is a three character sequence that is replaced by a corresponding single character. Table 33 gives the complete list of trigraph sequences and their replacement characters.
 
Table 33: Trigraph Sequences and Replacement Characters 
Trigraph Sequence  Replacement 
??=
??/ \
??" ^
??( [
??) ]
??! |
??< {
??> }
??- ~

Any ? that does not begin one of the trigraphs listed above is not changed.

-notrigraph option

In the ANSI extended (-Ae) mode, trigraph translation is automatically done. The option, -notrigraph will disable automatic translation of trigraph sequence.

HP C Compiler Options

Table 6: HP C Compiler Options at a Glance summarizes the command line options supported by HP 9000 workstations and servers. See Table 7: HP C Compiler Option Details for detailed information about each option.
 

Table 8: HP C Compiler Options at a Glance 
Option  Description 
-Aa Enables strict ANSI C compliance.
-Ac Disables ANSI C compliance (HP C version 3.1 compatibility).
-AC99 Use this option for C99 specific features. This option enables recognition of keywords like restrict, and typeof.
(Without this option, the keywords __restrict__ and __typeof__ need to be used).
-Ae Enables ANSI C compliance, HP value-added features (as described for +e option), and _HPUX_SOURCE name space macro. It is equivalent to -Aa +e -D_HPUX_SOURCE.
-Bextern Performs the same operation as +Oextern=sym1,sym2,sym3... except that symbols are loaded from an existing file, instead of specified on the command line.
-Bhidden Hides all the symbols including references except for those prefixed with __declspec(dllexport), __declspec(dllimport).
-Bhidden_def Hides all the symbols defined in the module except for those prefixed with __declspec(dllexport).
-c Compiles only, does not link.
-C Prevents the preprocessor from stripping comments.
-Dname Defines the preprocessor variable name with a value of "1".
-Dname=def Defines the preprocessor variable name with a value of def.
-dynamic Enables linking of PIC objects.
-E Performs preprocessing only with output to stdout.
-fast Expands into a set of compiler options which results in improved application run-time. Options included are +O3, +Onolooptransform, +Olibcalls, +FPD, +Oentryschedule, and +Ofastaccess. Any of these options can be overridden by placing a subsequent option after -fast on the command line.
-g Inserts information for the symbolic debugger in the object file.
-G Inserts information required by the gprof profiler in the object file.
-Idir Inserts dir in the include file search path.
-include <file> Causes the compiler to insert <file> at the beginning of a set of translation units, before processing them.
-lx Links with the /lib/libx.a and /usr/lib/libx.a libraries.
-Ldir Links the libraries in dir before the libraries in the default search path.
-n Generates shareable code.
-N Generates unshareable code.
-noshared Creates statically-bound executables.
-o outfile Places object modules in outfile file.
-O Optimizes at level 2.
-p Inserts information required by the prof profiler in the object file.
-P Performs preprocessing only with output to the corresponding .i file.
-q Marks the executable as demand loadable.
-Q Marks the executable as not being demand loadable.
-s Strips the symbol table from the executable file.
-S Generates an assembly language source file.
-t x,name Substitutes or inserts subprocess x with name.
-Uname Undefines name in the preprocessor.
-v Enables verbose mode.
-V Causes subprocesses to print version information to stderr.
-w Suppresses warning messages.
-Wd,-a or +a Omits HP provided prefix files required by the linker.
-Wx, arg1 [,arg2,..,argn] Passes the arguments arg1 through argn to the subprocess x.
-y Generates information used by the HP SoftBench static analysis tool.
-Y Enables Native Language Support (NLS).
-z Disallows run-time dereferencing of null pointers.
-Z Allows dereferencing of null pointers at run-time.
+DAmodel Generates object code for a specific version of the PA-RISC architecture.
+DCapptype Generate code for portable or embedded applications.
+DD32 Generates 32-bit code for PA1.1 architecture.
+DD64 Generates 64-bit code for PA2.0 architecture.
+dfname Specifies the profile database to use with profile-based optimization.
+DSmodel Performs instruction scheduling for a specific implementation of PA-RISC.
+DOosname Sets the target operating system for the compiler.
+e Enables the following HP value added features while compiling in ANSI C mode: sized enum, long long, long pointers, compiler supplied defaults for missing arguments to intrinsic calls, and $ in identifier HP C extensions.
+ESfic Compiles with inline fast indirect calls.
+ESconstlit Introduces new default behavior. HP C now stores constant-qualified (const) objects and literals in read-only memory.
+ESlit Places string literals and constants into read-only data storage.
+ESloc=name Creates a subspace by this name.
+ESnolit Disables +ESconstlit, causing HP C to no longer store literals in read-only memory.
+ESnoparmreloc Disables parameter relocation for function calls.
+ESsfc Replaces function pointer comparison millicode calls with inline code.
+f Inhibits the promotion of float to double, except for function calls and returns.
+FPflags Controls floating-point traps.
+help Launches a web browser displaying an html version of the HP C/HP-UX online help.
+hugesize Lowers the threshold for huge data.
+I Prepares the object code for profile-based optimization data collection.
+k Generates long-displacement code sequences so a program can reference large amounts of global data physically located in shared libraries.
+L Enables any #pragma listing directives and the listing facility.
+m Prints identifier maps in the source code listing.
+M Provides ANSI migration warnings that explain the differences between code compiled with -Ac and -Aa.
+M1 Provides platform migration warnings for features that may not be supported in future releases.
+M2 Provides migration warnings for transitioning code from the ILP32 to the LP64 data model.
+o Prints hexadecimal code offsets in the source code listing.
+[no]objdebug When used with -g, +objdebug leaves debug information in the object files instead of copying it to the executable file. The object files must be accessible to the HP WDB debugger when debugging. This option is not supported by the HP DDE debugger.
+Oopt Invokes optimization level opt where opt is 0 to 4. See the HP C/HP-UX Programmer's Guide for additional optimization options.
+P Performs profile-based optimization.
+pa Requests routine-level profiling with CXperf.
+pal Requests routine-level and loop-level profiling with CXperf.
+pgmname Specifies the execution profile data set to be used by the optimizer.
+r Inhibits the automatic promotion of float to double.
+ub Unqualified bit fields are treated as unsigned.
+sb Make bit-fields signed by default in both 32- and 64-bit modes.
+ubytes Controls pointer alignment where bytes is 1, 2, or 4.
+uc Makes unqualified char data types unsigned.
+wn Specifies the level of the warning messages where n is 1 - 3.
+W n1[,n2,...nN] Suppresses the specified warnings.
+We[n1,n2,...nN] Changes the specified warnings to errors. In the absence of warning numbers, all warnings are turned into error messages.
+Wwn1[,n2,...nN] Enables the specified warnings, assuming all other warnings are suppressed with -w or +w3.
+z Generates shared library object code (same as +Z in 64-bit mode).
+Z Generates shared library object code with a large data linkage table (long-form PIC).

Table 6: HP C Compiler Option Details describes in detail the options that HP C workstations and servers support.
 

Table 6: HP C Compiler Option Details 
Option  What It Does 
-Aa Requests a compilation in ANSI C mode. The -Aa option requests a strict implementation of ANSI C. ANSI C specifies which names are available in the standard libraries and headers, which are reserved for the implementation, and which must be left available for you. HP C in ANSI mode conforms to these restrictions and only names permitted by ANSI C are defined or declared in the standard libraries and headers. Macro definitions can be used to access names that are normally defined in other standards (POSIX and XOPEN, for example), and in HP C Version 3.1 compatibility mode. To gain access to all variables and functions defined by POSIX, include the following line at the start of your source file before including any system headers: 
#define _POSIX_SOURCE
or define this macro by using the -D name option: 
cc -D _POSIX_SOURCE  myfile.c
To gain access to all the names defined by XOPEN, include the following line at the start of your source file before including any system headers: 
#define _XOPEN_SOURCE
or define the macro on the command line: 
cc -D _XOPEN_SOURCE myfile.c
To gain access to all the names normally available in compatibility mode, include the following line at the start of your source file before including any system headers: 
#define _HPUX_SOURCE
or define the macro on the command line: 
cc -D _HPUX_SOURCE myfile.c
_HPUX_SOURCE defines a superset of names defined by _XOPEN_SOURCE. _XOPEN_SOURCE defines a superset of names defined by _POSIX_SOURCE.
-Ac Requests compatibility with version 3.1. This was the default at the HP-UX 10.20 operating system release. It is a non-ANSI implementation.
-Ae Requests a compilation in ANSI C mode with HP C extensions. This option is the same as specifying -Aa, -D_HPUX_SOURCE, and +e. This is the default for the HP-UX 10.30 and later operating system releases.
-Bextern Performs the same operation as +Oextern=sym1,sym2,sym3... except that symbols are loaded from an existing file, instead of specified on the command line. -Bextern does not require that you manually specify symbols locally, on the command line. In fact, if you specify a locally-defined symbol with -Bextern, you may experience problems.
When used, -Bextern tells the compiler that the symbols reside in a separate load module. -Bextern:filename fetches the list of symbols from a text file instead of locally. Symbols referenced in the file must be separated by white space within the file.
-Bhidden Hides all the symbols including references except for those prefixed with __declspec(dllexport), __declspec(dllimport) or specified with +Oextern or HP_DEFINED_EXTERNAL pragma. This will hide both definitions and references.
-Bhidden_def Hides all the symbols defined in the module except for those prefixed with __declspec(dllexport). This will hide only definitions.
-c Compiles one or more source files but does not enter the linking phase. The compiler produces the object file (a file ending with .o by default) for each source file (a file ending with .c, .s, or .i). Object files must be linked before they can be executed.
-C Prevents the preprocessor from stripping comments. See the description of cpp(1) in the HP-UX Reference Manual for details.
-Dname -Dname=def Defines name to the preprocessor cpp as if defined by the preprocessing directive #define. If =def is not given, name is "1". Macros should be assigned integer values when they will be used in constant expressions that are to be evaluated by the conditional compilation directives #if and #else. See Conditional Compilation (#if, #ifdef,..#endif) for more information.
-dynamic This option produces dynamically bound executables. These support shared libraries and use the features of the dynamic loader. The shl_load and dlopen APIs are fully supported. The linker links in shared libraries first and then archive libraries. Only PIC is supported.
-E Runs the preprocessor only on the named HP C or assembly programs and sends the result to standard output (stdout).
-fast The -fast compiler option expands into an existing set of compiler options which, used together, result in optimum speed and application run-times. This option is also provided for compatibility in porting Sun- and SGI-compiled applications to HP-UX.

NOTE: Do not use this option for programs that depend on IEEE standard floating-point denormalized numbers. Otherwise, different numerical results may occur.
-fast expands to the following HP C/ANSI C options:

+O3 +nolooptransform +Olibcalls +FPD +Oentrysched +Ofastaccess

  • +O3 optimizations include all +O2 optimizations as well as all subprograms within a single file. It also inlines certain subprograms within the input file.
  • +Onolooptransform disables transformation of eligible loops for improved cache performance.
  • +Olibcalls increases the runtime performance of code which calls the standard library routines.
  • +FPD enables a fast underflow mode on PA-7100 architectures or later where denormalized floating-point operands are flushed to zero.
  • +Oentrysched optimizes instruction scheduling on a procedure's entry and exit sequences.
  • +Ofastaccess optimizes code for fast access to global data items.
You can override any of the options in -fast by specifying a subsequent option after it. 
-g Inserts information for the symbolic debugger in the object file. In conjunction with the HP Distributed Debugging Environment (DDE), the C compiler now provides support for debugging optimized code. This support includes: 
  • Tracebacks with line-number annotation
  • Setting breakpoints and single-stepping at the source statement level
  • Mapping between source statements and machine instructions
  • Viewing and modifying global variables at procedure call boundaries
  • Viewing and modifying parameters on procedure entry
To enable debugging of optimized code, specify the -g compile-line option together with the -O, +O1, or +O2 option. Currently, debugging is supported at optimization levels 2 and below. If you try to use -g with the +O3 or +O4 option, the compiler will issue a warning stating that the options are incompatible, and will ignore the -g option.
-G Prepares the object file for profiling with gprof. See the gprof(1) description in the HP-UX Reference Manual for details.
-Idir Adds dir to the list of directories that are searched for include files by the preprocessor. For include files that are enclosed in double quotes and do not begin with a /, the preprocessor first searches the current directory, then the directory named in the -I option, and finally, the standard include directory /usr/include. For include files that are enclosed in < and > symbols, the search path begins with the directory named in the -I option and is completed in the standard include directory, /usr/include. The current directory is not searched.
-include <file> This option causes the compiler to insert <file> at the beginning of a set of translation units before processing them. Effectively, it executes implicit #include "<file>" directives for each -include <file> option on the command line, before the very first line of each of the source files specified on the command line.

This is a GCC compatibility feature.

Example Usage:
$ cc [cc opts] [-include <file>]* [cc opts] <source file(s)>
where, [-include ]* stands for zero or more -include options.

All the -include options are processed in the order in which they are written.

-lx Causes the linker to search the libraries /usr/lib/libx.a or /usr/lib/libx.sl (searched first) and /opt/langtools/lib/libx.a or /opt/langtools/lib/libx.sl (searched second). The -a linker option determines whether the archive (.a) or shared (.sl) version of a library is searched. The linker searches the shared version of a library by default. Libraries are searched when their names are encountered. Therefore placement of a -l is significant. If a file contains an unresolved external reference, the library containing the definition must be placed after the file on the command line. See the description of ld(1) in the HP-UX Reference Manual for details.
-Ldir Causes the linker to search for libraries in the directory dir before using the default search path. The default search path is the directory /usr/lib followed by /opt/langtools/lib. -Ldir must precede -lx on the command line; otherwise -Ldir is ignored. This option is passed directly to the linker. For example: 
cc -L/project/libs prog.c -lfoo -lbar
Compiles and links prog.c and directs the linker to search the directories /project/libs, /usr/lib, then /opt/langtools/lib for libfoo.a, libfoo.sl, libbar.a, and libbar.sl libraries.
-n Causes the program file produced by the linker to be marked as shareable. For details and system defaults see the description of ld(1) in the HP-UX Reference Manual.
-N Causes the program file produced by the linker to be marked as unshareable. For details and system defaults see the ld(1) description in the HP-UX Reference Manual.
-noshared Creates statically bound executables. This option is available with option +DA2.0W only. See -dynamic for dynamically bound executables. The default behavior is dynamic.
-o outfile Causes the output of the compilation sequence to be placed in outfile. The default name is a.out. When compiling a single source file with the -c option, you can also use the -o option to specify the name and location of the object file.
-O Invokes the optimizer to perform level 2 optimization. Other optimization levels can be set. Refer to the HP C/HP-UX Programmer's Guide for details on optimization. 
-p Causes the compiler to produce extra profiling code that counts the number of times each routine is called. Also, if link editing takes place, this option replaces the standard startup routine with a routine that calls monitor(3C) at the start and writes out a mon.out file upon normal termination of the object program's execution. An execution profile can then be generated using prof(1).
-P Preprocesses only. Runs the preprocessor with the -P option only on the named HP C source files and leaves the result in the corresponding files with .i as the suffix.
-q Causes the output file from the linker to be marked as demand loadable. For details and system defaults, see the ld(1) description in the HP-UX Reference Manual.
-Q Causes the program file created by the linker to be marked as not demand loadable. For details and system defaults, see the ld(1) description in the HP-UX Reference Manual.
-s Strips the executable. Causes the program file created by the linker to be stripped of symbol table information. Specifying this option prevents using a symbolic debugger on the resulting program. See the ld(1) description in the HP-UX Reference Manual for more details.
-S Compiles the named HP C program and leaves the assembly language output in a corresponding file with .s as the suffix.
-t x,name Substitutes or inserts subprocess x with name, where x is one or more of a set of identifiers indicating the subprocesses. This option works in two modes: 1) if x is a single identifier, name represents the full pathname of the new subprocess; 2) if x is a set of identifiers, name represents a prefix to which the standard suffixes are concatenated to construct the full pathnames of the new subprocesses. x can be one or more of the following values: 
  • p-Preprocessor (standard suffix is cpp).
  • c-Compiler (standard suffix is ccom).
  • 0-Same as c.
  • a-Assembler (standard suffix is as).
  • l-Linker (standard suffix is ldr).
-Uname Undefines or removes any initial definition of name in the preprocessor. See the cpp(1) description in the HP-UX Reference Manual for details.
-v Enables the verbose mode sending a step-by-step description of the compilation process to standard error (stderr.)
-V Prints version information on each invoked subprocess to standard error (stderr.)
-w Suppresses warning messages.
-Wx, arg1[,arg2,..,argn] Passes the arguments arg1 through argn to the subprocess x of the compilation. x can be one of the values described under the -t option with the addition of d, to pass an option to the cc driver. These options are HP value added extensions to HP C.
-W c,-e or +e Enables the following HP value added features while compiling in ANSI C mode: sized enum, long long, long pointers, compiler supplied defaults for missing arguments to intrinsic calls, and $ in identifier HP C extensions.
-W c,-L or +L Enables any #pragma listing directives and the listing facility. A straight listing prints the following: 
  • A banner on the top of each page.
  • Line numbers.
  • The nesting level of each statement or declaration.
  • The post processed source file with expanded macros, include files, and no user comments (unless the -C option is used).
Under ANSI mode, -Wc,-L causes the compiler to generate an output list of the source without the cpp macro replacements. The -Wc,-Lp option causes the compiler to generate an output list of the source with the cpp macro replacements.
-W c,-m or +m Causes the identifier maps to be printed. First, all global identifiers are listed, then all the other identifiers are listed by function at the end of the listing. For struct and union members, the address column contains B@b, where B is the byte offset and b is the bit offset. Both B and b are in hexadecimal.
-W c,-o or +o Causes the code offsets to be printed in hexadecimal grouped by function at the end of the listing.
-W c, or -Rnum Allow only the first num register variables to actually have the register class. Use this option when the register allocator issues an out of general registers message.
-W c,-wn or +wn Specifies the level of the warnings messages. The value of n can be one of the following:
  • 1-All warnings are issued. This includes low level warnings that may not indicate anything wrong with the program.
  • 2-Only warnings indicating that code generation might be affected are issued. This is equivalent to the compiler default without the -w options.
  • 3-No warnings are issued. This is equivalent to the -w option.
-W d,-a When processing files written in assembly language, this option specifies that the compiler should not assemble with the prefix file that sets up the space and subspace structure required by the linker. Programs assembled with this option may not link unless they contain the equivalent information. You can then optimize the program based on this profile data by re-linking with the +P command line option. The +I command line option is incompatible with the -g, -p, -s, -S, and -y options. The +I option does not affect the default optimization level or the optimization level specified by the -O or +O options. For more details on invoking profile-based optimization, refer to the HP C/HP-UX Programmer's Guide.
-y Requests the compiler to generate additional information for the static analysis tool, which is a part of the HP SoftBench software development environment. See HP Softbench Static Analyzer: Analyzing Program Structure for more information.
-Y Enables Native Language Support (NLS) of 8-bit and 16-bit characters in comments, string literals, and character constants. See hpnls(5), long(5), and environ(5) in the HP-UX Reference Manual for a description of the NLS model. The language value is used to initialize the correct tables for interpreting comments, string literals, and character constants. It is also used to build the pathname to the proper message catalog. 
-z Disallows run-time dereferencing of null pointers. Fatal errors result if null pointers are dereferenced.
-Z Allows dereferencing of null pointers at run-time. (This behavior is the default.) The value of a dereferenced null pointer is zero.
+DAmodel Generates object code for a particular version of the PA-RISC architecture. If you do not specify this option, the default object code generated is determined automatically as that of the system on which you compile. +DA also specifies which version of the HP-UX math library to link in when you specify -lm. (See the HP-UX Floating-Point Guide for more information about using math libraries.) model can be a model number of an HP 9000 system (such as, 730, 877, H50, or I50), one of the PA-RISC architecture designations 1.1, 2.0, 2.0W, or portable. For example, specifying +DA1.1 or +DA735 generates code for the PA-RISC 1.1 architecture. Similarly, specifying +DA2.0 generates 32-bit code for the PA-RISC 2.0 architecture. Specifying +DA2.0W generates 64-bit ELF object files for the PA-RISC 2.0 architecture. Specifying +DAportable generates code compatible across all HP 9000 workstations and servers. See the file /opt/langtools/lib/sched.models for model numbers and their architectures. Use the command uname -m to determine the model number of your system.

Note: Object code generated for PA-RISC 2.0 will not execute on PA-RISC 1.1 systems. Object code generated for the 64-bit data model (LP64) will not execute under the 32-bit data model (ILP32). To generate code compatible across PA-RISC 1.1 and 2.0 workstations and servers, use the +DAportable option. For best performance, use +DA with the model number or architecture where you plan to execute the program. Starting at the HP-UX 10.20 release, the default object code generated by HP compilers is determined automatically as that of the machine on which you compile. (Previously, the default code generation was PA-RISC 1.0 on Series 800 servers, and PA-RISC 1.1 on Series 700 workstations.) For more information on this option, see Using +DA to Generate Code for a Specific Version of PA-RISC .

See also the +DD32 and +DD64 options.

+DCapptype Generate code for portable or embedded applications (64-bit mode only.) When apptype is hpux, the compiler builds portable applications. This is the default behavior, and is equivalent to using +Oextern. When apptype is emb, the options most commonly used to generate embedded systems code are enabled. Note that code generated with the +DCemb must not be included in a shared library.
+DD32 Generates 32-bit object code for the PA-RISC 1.1 architecture, which runs on PA1.1 and PA2.0 architectures. This option is the same as the options +DA1.1 and +DAportable.
+DD64 Generates 64-bit object code for PA2.0 architecture. Causes the macros __LP64__ and _PA_RISC2_0 to be #defined. This is the same as +DA2.0W, but is the recommended option to use when compiling in 64-bit mode on the PA RISC 2.0 architecture because it is forward compatible with future 64-bit architectures.
+dfname Specifies the path name of the profile database to use with profile-based optimization. This option can be used with the +P command line option. The profile database by default is named flow.data. This file stores profile information for one or more executables. Use +df when the flow.data file has been renamed or is in a different directory than where you are linking. You can also use the FLOW_DATA environment variable to specify a different path and file name for the profile database file. The +dfname command line option takes precedence over the FLOW_DATA environment variable. Note, the +dfname option cannot be used to redirect the instrumentation output (with the +I option). It is only compatible with the +P option.
+DOosname Sets the target operating system for the compiler. The osname can be:
  • 11.0EP9806 (indicates the HP-UX 11.0 EXTPAK 9806 release) 
  • 11.0 (the default)
  • 11.11
If +DO11.0EP9806 and +Olibcalls are both specified on an HP-UX 11.0EP9806 system, the compiler enables the fusing of math library calls where applicable. This promotes instruction level parallelism by computing the same function (such as sin()) of two values concurrently.

+DO can be used at any optimization level. By default, when you compile your application, it is binary compatible across the 11.x release. You only need to specify +DO when you want the latest performance features supported in the OS.

Caution: Use of +DO with a non-default osname makes the resulting code binary incompatible with an earlier version of HP-UX.

+DSmodel Performs instruction scheduling tuned for a particular implementation of the PA-RISC architecture. model can be a model number of an HP 9000 system (such as 730, 877, H50, or I50); a PA-RISC architecture designation 1.1 or 2.0; or a processor name (such as PA7100LC). For example, specifying +DS720 performs instruction scheduling tuned for one implementation of PA-RISC 1.1. Specifying +DSPA7100LC performs scheduling for a system with a PA7100LC processor. Specifying +DSPA8000 performs instruction scheduling for systems based on the PA-RISC 8000 processor. To obtain the best performance on a particular model or processor of the HP 9000, use +DS with that model number or processor name. If you plan to run your program on both PA-RISC 1.1 and 2.0 systems, in general we recommend you use +DS2.0. See the file /opt/langtools/lib/sched.models for model numbers and the processor names for which implementation-specific scheduling is performed. Use the command uname -m to determine the model number of your system. Object code with scheduling tuned for a particular model or processor will execute on other HP 9000 systems, although possibly less efficiently. For more information on this option, see Using +DS to Specify Instruction Scheduling .
+e See -W c,-e
+ESfic The +ESfic option generates code for fast indirect calls. This option should only be used in an environment where there are no dependencies on shared libraries. The application must be linked with archive libraries. Using this option can improve run-time performance.
+ESconstlit Introduces a new default behavior for the HP C compiler, in which HP C stores constant-qualified (const) objects and literals in read-only memory. Storing const-qualified string literals in read-only memory can cause a program which violates the semantics of const to abnormally terminate with a bus error and core dump. This is because literals, which have been placed in read-only memory, may not be modified at runtime. See the description of +ESnolit for details on how to specify that literals not be placed in read-only memory.
+ESlit Places string literals and constants defined with the ANSI C const type qualifier into the $LIT$ subspace. The $LIT$ subspace is used for read-only data storage. This option can reduce memory requirements and improve run-time speed in multi-user applications. Normally the C compiler only places floating-point constant values in the $LIT$ subspace, and other constants and literals in the $DATA$ subspace. This option allows the placement of large data objects, such as ANSI C const arrays, into the $LIT$ subspace. All users of an application share the static data stored in the $LIT$ subspace. Each user is allocated a private copy of the dynamic data stored in the $DATA$ subspace. By moving additional static data from the $DATA$ subspace to the $LIT$ subspace, overall system memory requirements can be reduced and run-time speed improved. Most applications can benefit from this option. Users should not attempt to modify string literals if they use the +ESlit option. The reason is that this option places all string literals into read-only memory. Particularly, the following C library functions should be used with care, since they can alter the contents of string literals if users specify string literals as the receiving string. 
extern char *strncat(char *, const char *, size_t);
extern void *memmove(void *, const void *, size_t);
extern char *strcpy(char *, const char *);
extern char *strncpy(char *, const char *, size_t);
extern char *strcat(char *, const char *);
extern char *strtok(char *, const char *);
+ESloc=name This option will create a subspace by this name and will put all data and code in the relocatable object module by this name.
+ESnolit +ESnolit disables the default behavior of the HP C compiler to store literals in read-only memory. Specifying this option causes HP C to no longer store literals in read-only memory. This restores HP C's traditional behavior prior to this release of the compiler.
+ESnoparmreloc +ESnoparmreloc disables parameter relocation for function calls. If your source code uses the ANSI C function prototype consistently in both declaration and definition of a function, this option may allow you to produce smaller and faster function entry code. The library is compiled with this option off. So, to use this option in your code, you must declare the library functions without function prototype. For example, cos has not been compiled with +ESnoparmreloc. If you declare cos with a function prototype as shown below, and compile with +ESnoparmreloc, an incorrect value will be passed to cos()
double cos(double);
main()
   {
   printf("%f\n", cos(1.0));
   }
For more information on parameter relocation, see the HP PA-RISC Procedure Calling Conventions Reference Manual, HP part number 09740-90015.
+ESsfc Replaces millicode calls with inline code when performing simple function pointer comparisons. The +ESsfc compiler option affects how function pointers are compared in generated code. The default is to generate low-level millicode calls for function pointer comparisons. The +ESsfc option generates code that compares function pointers directly, as if they were simple integers. The +ESsfc option should only be used in an environment where there are no dependencies on shared libraries. The application must be linked with archive libraries. Using this option can improve run-time performance.
+f Inhibits the automatic promotion of float to double when evaluating expressions. This differs from the +r option in that both parameters and function return values are still promoted to double. In ANSI mode, this option is ignored and a warning is issued.
+FPflags Specifies what floating-point traps to enable and also enables or disables fast underflow mode. flags is a series of upper case or lower case letters from the set [VvZzOoUuIiDd] with no spaces, tabs, or other characters between them. If the upper-case letter is selected, that behavior is enabled. If the lower-case letter is selected or if the letter is not present in the flags, the behavior is disabled. By default, all traps are disabled. The values for flags are:
  • V enables traps on invalid floating-point operations.
  • v disables traps on invalid floating-point operations.
  • Z enables traps on divide by zero. (If your program must conform to the POSIX standard, do not enable this trap.)
  • z disables traps on divide by zero.
  • O enables traps on floating-point overflow.
  • o disables traps on floating-point overflow.
  • U enables traps on floating-point underflow.
  • u disables traps on floating-point underflow.
  • I enables traps on floating-point operations that produce inexact results.
  • i disables traps on floating-point operations that produce inexact results.
 
  • D enables fast underflow (flush to zero) of denormalized values. (Enabling fast underflow is an undefined operation on PA-RISC 1.0 based systems, but it is defined on all subsequent versions of PA-RISC. Selecting this value enables fast underflow only if it is available on the processor that is used at run time.)
  • d disables fast underflow (flush to zero) of denormalized values.
To dynamically change these settings at run time, refer to fpgetround(3M).
+help Launches a web browser displaying an html version of the HP C/HP-UX online help, and then processes any other arguments.
+hugesize=n[M][K] Lowers the threshold for huge data.
  • n is an integer with a maximum value of 258 bytes.
  • M indicates megabytes.
  • K indicates kilobytes.
  • M or K are optional specifiers. If neither is specified the default is K.
In order for the compiler to qualify a data object as huge, its size must exceed the current setting of the hugesize threshold. The threshold is initially set to 256 megabytes (228 bytes). A data object whose size exceeds the threshold is allocated in huge subspace. 

The compiler puts all small arrays, structures, and unions into a separate subspace. An application with too many arrays may run out of subspace creating an overflow condition. In this case linking fails. One way to solve this problem is to lower the threshold so that any array greater than or equal to the threshold (in bytes) is put into the huge data subspace instead.

The following example lowers the threshold to 223 (8 megabytes) resulting in more data objects being put in huge subspace: 

cc +DD64 +hugesize=8M app1.c app2.c
For more information, see cc +help.
+I Instructs the compiler to instrument the object code for collecting run-time profile data. The profiling information can then be used by the linker to perform profile-based optimization. Code generation and optimization phases are delayed until link time by this option. After compiling and linking with +I, run the resultant program using representative input data to collect execution profile data. Profile data is stored in flow.data by default. See the +dfname option for information on controlling the name and location of this data file.
+k Generates long-displacement code sequences so a program can reference large amounts of global data that is physically located in shared libraries. Only use +k when you get a linker message indicating you need to use it. By default, the HP C compiler generates short-displacement code sequences for programs that reference global data that is physically located in shared libraries. For nearly all programs, this is sufficient. If your program references a large amount of global data in shared libraries, the default code generation for referencing that global data may not be sufficient. If this is the case, when you link your program the linker will give an error message indicating that you need to recompile your program with the +k option.
+L See -W c,-L
+m See -W c,-m
+M0 (or +M) Emits ANSI C migration warnings. Use the +M option with either -Aa or -Ac. These were formerly part of +w1. The document ANSI Programming Language C Standard ISO 9899:1990 discusses the behavioral differences in code that is migrated to ANSI C. These differences are called quiet changes.
+M1 Emit warnings for possible problems connected with platform migration.
+M2 Emit warnings for possible problems connected with migration to the LP64 data model (64-bit mode). This option is only available in 64-bit mode. Refer to the HP-UX 64-bit Porting and Transition Guide for details.
+o See -W c,-o
+[no]objdebug When used with -g, +objdebug leaves debug information in the object files instead of copying it to the executable file at link time, resulting in shorter link times and smaller executables. The default, +noobjdebug, copies the debug information to the executable file.

When you specify -g, the compiler places symbolic debugging information into the object files. By default, the linker calls pxdb which compacts this debug information & copies it to the executable file. When +objdebug was used at compile time, the linker leaves the debug information in the object files. To debug the executable file, the HP WDB debugger must have access to the object files. If you move the object files, use HP WDB's objdir command to tell it where the object files are. (The HP DDE debugger does not support this option.) This option reduces link time and the size of the executable file by avoiding this copying of debug information.

The compile-time default is +noobjdebug. If the linker detects any object files that were compiled with +objdebug, it will leave the debug information in those files. Any object files not compiled with +objdebug will have their debug information copied into the executable file. You can leave debug information in some object files and not in others. 

Use the +noobjdebug option when linking to explicitly tell the linker to copy all debug information to the executable file, even from files compiled with +objdebug.

+Oopt Invokes the level of optimization selected by opt. opt can have any of the following values. 
  • 1 performs level 1 optimizations.
  • 2 performs level 1 and 2 optimizations.
  • 3 performs level 1, 2, and 3 optimizations.
  • 4 performs level 1, 2, 3, and 4 optimizations.
For a complete list of advanced optimization toggles, see .
+P Directs the compiler to use profile information to guide code generation and profile-based optimization. This option causes the compiler to generate intermediate compiler code instead of compiled object code. The actual code generation is done at link time. The +P option does not affect the default optimization level, or the optimization level specified by the -O or +Oopt options. Note: Source files that are compiled with the +I option do not need to be recompiled with +P in order to use profile-based optimization. You only need to relink the object files with the +P option after running the instrumented version of the program. The +P command line option is incompatible with the +I, -g, -s, -S, and -y options. Also refer to the +I, +pgm and +df command line options. For more information on using these options, see the HP C/HP-UX Programmer's Guide.
+pa Requests that the application be compiled for routine-level profiling with CXperf. The +pa option is not valid with the +O4 or +Oall optimization options. Also, +pa is not compatible with the -p or -G options. For more information, see the CXperf Online Help or CXperf Command Reference.
+pal Requests that the application be compiled for routine-level and loop-level profiling with CXperf. The +pal option is not valid with the +O4 or +Oall optimization options. Also, +pal is not compatible with the -p or -G options. For more information, see the CXperf Online Help or CXperf Command Reference.
+pgmname Specifies a program name to look up in the flow.data file. Used with profile-based optimization and the +P option. +pgmname should be used when the name of the profiled executable differs from the name of the current executable specified by the -o option.
+r Inhibits the automatic promotion of float to double when evaluating expressions and passing arguments. This option is not valid in ANSI mode.
+ub This option treats unqualified char, short, int, long and long long bitfields as unsigned. This option has no effect on signedness of enum bitfields or on signedness of non-bitfield character
+sb Use signed bitfields (in 32- and 64-bit modes). By default, unqualified bitfield types are signed in 32-bit mode and unsigned in 64-bit mode.
+ubytes Forces all pointer references to assume that data is aligned on either an 8-bit, 16-bit, or 32-bit addresses. bytes can be 1 (8-bit), 2 (16-bit), or 4 (32-bit). The default value for +u is 2. This option can be used when reading in non-natively aligned data. Pragmas are also available to assist with processing non-natively aligned data. Refer to Chapter 2, "Storage and Alignment Comparisons," in the HP C/HP-UX Programmer's Guide for detailed information on the HP_ALIGN and PACK pragmas.
+uc Makes unqualified char data types unsigned. By default, the HP C compiler makes all unqualified char data types signed. Use this option to help port applications from other vendor platforms, where the default behavior for unqualified char types is unsigned. Be careful when using this option. Your application may have trouble interfacing with HP-UX system libraries and other libraries that do not use this option.
+wn Specifies the level of the warnings messages. The value of n can be one of the following:
  • 1-All warnings are issued. This includes low level warnings that may not indicate anything wrong with the program.
  • 2-Only warnings indicating that code generation might be affected are issued. This is equivalent to the compiler default without the -w options.
  • 3-No warnings are issued. This is equivalent to the -w option.
This option is the same as -W c,-wn.
+W n1[,n2[,...nN]] Suppresses the specified warnings, where n1 through nN are valid compiler warning message numbers. See the file /opt/ansic/lib/nls/msg/C/cc.msgs for a list of error and warning messages.
+Wen1[,n2[,...nN]] Changes the specified warning to an error, where n1 through nN are valid compiler warning messages. See the file /opt/ansic/lib/nls/msg/C/cc.msgs for a list of compiler messages.
+Wwn1[,n2[,...nN]] Enables the specified warnings, assuming all other warnings have been suppressed with -w or +w3.n1 through nN are valid compiler warning messages. See the file /opt/ansic/lib/nls/msg/C/cc.msgs for a list of compiler messages.
+z Generates object code that can be added to a shared library. Object code generated with this option is position independent, containing no absolute addresses. All addresses are either pc-relative or indirect references. This is the same as the +Z option in 64-bit mode. The -p and -G options are incompatible with this option and are ignored. See the HP-UX Linker and Libraries Online User Guide for detailed information on shared libraries.
+Z This option is similar to +z with the difference being that space for more imported symbols is allocated. The size of the data linkage table allocated by the +z and +Z options is machine dependent. Use the +Z option when the linker ld issues an error message indicating data linkage table overflow. +Z is the default in 64-bit mode. For more information on shared libraries, see the HP-UX Linker and Libraries Online User Guide.
Any other option encountered generates a warning to standard error (stderr.) (Options not recognized by cc are not passed on to ld. Use the -Wl,arg option to pass options to ld.)  

Examples of Compiler Commands

Environment Variables

This section describes the following environment variables you can use to control the C compiler:

CCOPTS Environment Variable

You can pass arguments to the compiler using the CCOPTS environment variable or include them on the command line. The CCOPTS environment variable provides a convenient way for establishing default values for cc command line options. It also provides a way for overriding cc command line options.

The syntax for the CCOPTS environment variable in C shell notation is:

setenv CCOPTS [options]
[ | [options]]
The compiler places the arguments that appear before the vertical bar in front of the command line arguments to cc. It then places the second group of arguments after any command line arguments to cc.

Options that appear after the vertical bar in the CCOPTS variable override and take precedence over options supplied on the cc command line.

If the vertical bar is omitted, the compiler gets the value of CCOPTS and places its contents before any arguments on the command line.

For example, the following in C shell notation

setenv CCOPTS -v
cc -g prog.c
is equivalent to
cc -v -g prog.c
For example, the following in C shell notation
setenv CCOPTS "-v | +O1"
cc +O2 prog.c
is equivalent to
cc -v +O2 prog.c +O1
In the above example, level 1 optimization is performed, since the +O1 argument appearing after the vertical bar in CCOPTS takes precedence over the cc command line arguments.

TMPDIR Environment Variable

Another environment variable, TMPDIR, allows you to change the location of temporary files that the compiler creates and uses. The directory specified in TMPDIR replaces /var/tmp as the default directory for temporary files. The syntax for TMPDIR in C shell notation is:

setenv TMPDIR altdir

where altdir is the name of the alternative directory for temporary files.

MAXERRORS Environment Variable

This release of HP C compiler provides support to specify the maximum number of errors emitted before the compilation aborts. In the earlier versions, the compiler stopped, if it recognized more than 99 errors while compiling. With this release, the maximum number of errors that the compiler emits can be tuned as required by setting the MAXERRORS environment variable.

HPC_DEBUG_COMPAT Environment Variable

HPC does not emit debug information for unused objects (structures, unions, etc.) anymore with the -g option. For getting the older behavior (emitting debug information for all objects, irrespective of whether they are used in the program or not), an environment variable HPC_DEBUG_COMPAT can be set in the environment along with the -g option in the compilation commandline. This environment variable does not have to be set to any particular value.

SDK/XDK Support

SDK/XDK, helps you in selecting the components, header files, and libraries installed in alternate locations. To enable this support in your compiler, you need to set either one or both of the following environment variables:

Setting SDKROOT Environment Variable

The SDKROOT environment variable is used as a prefix for all references to tool set components. This environment variables is set by the user while using a non-native development kit or toolset installed at an alternative location. Some of the toolset components are compiler drivers, compiler applications, preprocessor, linker, and object file tools. If the HP C compiler has its tool set installed in /opt/xdk-ia/ directory then the command:
export SDKROOT=/opt/xdk-ia
will prefix all references to the HP C compiler tool set components with /opt/xdk-ia. The following details the default tool set components location as specified in the above command and its earlier location before the execution of the command:
 
Native location Alternate tool set location
/opt/ansic/bin/cc /opt/xdk-ia/opt/ansic/bin/cc
/opt/ansic/lbin/ccom  /opt/xdk-ia/opt/ansic/lbin/ccom
/opt/langtools/lbin/cpp /opt/xdk-ia/opt/langtools/lbin/cpp
/opt/ansic/lbin/ucomp /opt/xdk-ia/opt/ansic/bin/ucomp

Invoking the tool set components will actually result in the invocation of tool set components from the alternate location as specified above.

Setting TARGETROOT Environment Variable

The TARGETROOT environment variable is used as a prefix for all references to target set components. This environment variable is set by the user when using a non-native development kit. Some of the target set components are header files, archive libraries, and shared libraries. If the HP C compiler has its large tool set installed in /opt/xdk-ia/directory, the command:
export TARGETROOT=/opt/xdk-ia
will prefix all references to the target tool set components with /opt/xdk-ia. The following details the default location of the tool set components as specified in the above command and its earlier location before the execution of the command:
 
Native location Alternate tool set location
/usr/include /opt/xdk-ia/usr/include
/use/lib /opt/xdk-ia/usr/lib


NOTE  Options like -l or -L on the command line will override $TARGETROOT prefixing.

Compiling for Different Versions of the PA-RISC Architecture

This section describes the following compilation techniques for PA-RISC architectures:


Using +DA to Generate Code for a Specific Version of PA-RISC

By default, compiling on different HP 9000 systems produces code for the architecture of the system on which the compilation is performed. Use the +DA option to change this default behavior.

The +DA option specifies which PA-RISC instruction set the compiler should use when generating code. Specifying +DAportable ensures your code will run on HP PA-RISC 2.0 and 1.1 systems, although the performance of your program may not be as good as it could be if optimized for a specific system. Specifying +DA1.1 may give better performance on PA-RISC 1.1 systems, but the executable file generated with this option will not run on PA-RISC 1.0 systems. Specifying +DA2.0 gives optimal performance on PA-RISC 2.0 systems, but the program will not run on the earlier PA-RISC architectures.

Use the command uname -m to determine the model number of your system.

When you use the +DA option depends on your particular circumstance.

If you do not specify +DA or +DS, the default instruction scheduling is based on that of the system on which you compile. If you do specify a +DA option and do not specify a +DS option, the default instruction scheduling is based on what you specify in +DA, and not based on that of the system on which you compile. For example, if you specify +DA1.1 and do not specify +DS, and instruction scheduling will be for 1.1. If you specify +DAportable and do not specify +DS, and instruction scheduling will be for 1.1. (+DAportable is currently equivalent to +DA1.1.)

Using +DS to Specify Instruction Scheduling

Instruction scheduling is different on different implementations of PA-RISC architectures. You can improve performance on a particular model or processor of the HP 9000 by requesting that the compiler use instruction scheduling tuned to that particular model or processor. Using scheduling for one model or processor does not prevent your program from executing on another model or processor.

Use the +DS option to specify instruction scheduling tuned to a particular implementation of PA-RISC. Note that model can be a model number of an HP 9000 system (such as 730, 877, or H40); a PA-RISC architecture designation 1.1 or 2.0; or one of the PA-RISC processor names (such as PA7000, PA7100, PA7100LC, or PA8000.)

For example, to specify instruction scheduling for the model 867, use +DS867. To specify instruction scheduling for the PA-RISC 7100LC processor, use +DSPA7100LC. To specify instruction scheduling for systems based on the PA-RISC 8000 processor, use +DSPA8000.

If you plan to run your program on both PA-RISC 1.1 and 2.0 systems, in general we recommend you use the +DS2.0 designation.

See the file /opt/langtools/lib/sched.models for model numbers and processor names. Use the command uname -m to determine the model number of your system.

If you do not specify a +DA or +DS option, the default instruction scheduling is based on that of the system on which you compile. If you do specify a +DA option and do not specify a +DS option, the default instruction scheduling is based on what you specify in +DA, and not based on that of the system on which you compile. For example, if you specify +DA1.1 and do not specify +DS, and instruction scheduling will be for 1.1. Specify +DAportable and do not specify +DS, and instruction scheduling will be for 1.1. (+DAportable is currently equivalent to +DA1.1.)

When you use the +DS option depends on your particular circumstance.

Compiling in Networked Environments

When compiles are performed using diskless workstations or NFS-mounted file systems, it is important to note that the default code generation and scheduling are based on the local host processor. The system model numbers of the hosts where the source or object files reside do not affect the default code generation and scheduling.

Pragmas and Options

A #pragma directive is an instruction to the compiler. Include pragmas in your C source code where you want them to take effect. But do not include them within a function. A pragma has effect from the point at which it is included to the end of the translation unit (or until another pragma changes its status).

HP C provides you the following pragmas:

Refer to the HP C/HP-UX Programmer's Guide for information on parallel processing pragmas and for additional information.

Initialization and Termination Pragmas

This section describes the INIT and FINI pragmas. These allow the user to set up functions which are called when a load module (a shared library or executable) is loaded (initializer) or unloaded (terminator). For example, when a program begins execution, its initializers get called before any other user code gets called. This allows some set up work to take place. In addition, when the user's program ends, the terminators can do some clean up. When a shared library is loaded or unloaded with the shl_load or dlopen API, its initializers and terminators are also executed at the appropriate time.

INIT Pragma

#pragma INIT "string"
Use the compiler pragma INIT to specify an initialization function. The functions take no arguments and return nothing. The function specified by the INIT pragma is called before the program starts or when a shared library is loaded.

For example:

#pragma INIT "my_init"void my_init() { ... do some initializations ... }

FINI Pragma

#pragma FINI "string"
Use the compiler pragma FINI to specify a termination function. The function specified by the FINI pragma is called after the C program terminates by either calling the libc exit() function, returning from the main or _start functions, or when the shared library which contains the FINI is unloaded from memory. Like the function called by the INIT pragma, the termination function takes no arguments and returns nothing.

For example:

#pragma FINI "my_fini"void my_fini() { ... do some clean up ... }

The Linker +I Option

HP-UX 10.x style initializers are the same type supported in all HP-UX 10.x releases. These are called both before the user's code is started or a shared library is loaded as well as when the shared library is unloaded. The linker option +I is used to create this type of initializer.

The function returns nothing but takes two arguments. The first is a handle to the shared library being initialized. This handle can be used in calling shl_load API routines. The second is set to non-zero at startup and zero at program termination.

$ ld -b foo.o +I my_10x_init -o libfoo.slfont=*

#include <dl.h>
void my_10x_init(shl_t handle, int loading)
{
/* handle is the shl_load API handle for the shared library being initialized. 
/* loading is non-zero at startup and zero at termination. 
*/ if (loading) 
{
... do some initializations ... 
} else 
{... do some clean up ...
}
}
This type is only supported when creating a shared library (linker -b option). Also note that it may not be called when the user's program terminates. They are always called, however, if the library is explicitly unloaded as a result of a shl_load or dlopen API call. All three types (INIT, FINI, and +I) are supported in 64-bit links. Only HP-UX 10.x style initializers are supported in 32-bit links.

Intrinsic Pragmas

INTRINSIC Pragma

#pragma INTRINSIC intrinsic_name1
[user_name] [,intrinsic_name2]
    [user_name]...
Declares an external name as an intrinsic.

INTRINSIC_FILE Pragma

#pragma INTRINSIC_FILE "path"
Specifies the path of a file in which the compiler can locate information about intrinsic functions.

Copyright Notice and Identification Pragmas

The following pragmas can be used to insert strings in code.

COPYRIGHT Pragma

#pragma COPYRIGHT "string"
Places a copyright notice in the object file, using the "string" argument and the date specified using COPYRIGHT_DATE. If no date has been specified using #pragma COPYRIGHT_DATE, the current year is used. For example, assuming the year is 1990, the directive #pragma COPYRIGHT "Acme Software" places the following string in the object code:
(C) Copyright Acme Software, 1990. All rights reserved. No part
of this program may be photocopied, reproduced, or transmitted
without prior written consent of Acme Software.

COPYRIGHT_DATE Pragma

#pragma COPYRIGHT_DATE "string"
Specifies a date string to be used in a copyright notice appearing in an object module.

LOCALITY Pragma

#pragma LOCALITY "string"
Specifies a name to be associated with the code written to a relocatable object module. All code following the LOCALITY pragma is associated with the name specified in string. The smallest scope of a unique LOCALITY pragma is a function. For example, #pragma locality "mine" will build the name "$CODE$MINE$".

Code that is not headed by a LOCALITY pragma is associated with the name $CODE$. An empty "string" causes the code name to revert to the default name of $CODE$.

LOCALITY_ALL Pragma

#pragma LOCALITY_ALL "string"
The functionality of LOCALITY_ALL pragma is similar to the LOCALITY pragma. In addition to the LOCALITY pragma, LOCALITY_ALL pragma also puts the data along with the code to the relocatable object module as specified in the string.

VERSIONID Pragma

#pragma VERSIONID "string"
Specifies a version string to be associated with a particular piece of code. The string is placed into the object file produced when the code is compiled.

Data Alignment Pragmas

This section discusses the data alignment pragmas HP_ALIGN and PACK and their various arguments available on the HP 9000 workstations and servers, to control alignment across platforms. In the following discussion, a word represents a 32-bit data structure. Refer to Chapter 2, "Storage and Alignment Comparisons," in the HP C/HP-UX Programmer's Guide for detailed information on the HP_ALIGN and PACK pragmas.

HP_ALIGN Pragma

#pragma HP_ALIGN align_mode [PUSH]
 
#pragma HP_ALIGN POP
Data Alignment Stack
The PUSH and POP options allow functions to establish their own alignment environment for the duration of the function call, and restore the alignment environment previously in effect when exiting the procedure.

The HP_ALIGN pragma must have a global scope (outside of any function, enclosing structure, or union).

#pragma HP_ALIGN POP
This option to HP_ALIGN restores the previous alignment environment saved using the HP_ALIGN PUSH pragma by deleting the current alignment mode from the top of the stack. If the alignment stack is empty, the default alignment is made the current mode.
#pragma HP_ALIGN align_mode PUSH
This pragma saves the current alignment environment for later retrieval by pushing it into a last in, first out (LIFO) stack. The align_mode is made the new current alignment by placing it on the top of the stack.
Alignment Modes
align_mode can be any of the following values:
#pragma HP_ALIGN HPUX_WORD
Results in int and float types being halfword aligned (two-byte aligned), doubles being word aligned (four byte aligned), and all structs being at least halfword aligned. This is the default for the Series 300/400 computer.
#pragma HP_ALIGN HPUX_NATURAL_S500
Results in doubles being word aligned. This is the default for the Series 500 computer.
#pragma HP_ALIGN HPUX_NATURAL
Results in native alignment for the HP 9000 workstations and servers. The int and float types are word aligned, doubles are double-word aligned (8-byte aligned), and structs may be byte aligned depending upon the data types used within the structure.
#pragma HP_ALIGN NATURAL
Results in a superset of the above. Uses native alignment provided by HPUX_NATURAL, all structs and unions are at least halfword aligned, and DOMAIN bit-field mapping is used. (See Chapter 2, "Storage and Alignment Comparisons," in the HP C/HP-UX Programmer's Guide for details regarding Domain bit-fields.)
#pragma HP_ALIGN DOMAIN_NATURAL
Similar to NATURAL except long doubles are only 8 bytes long (treated as doubles).
#pragma HP_ALIGN DOMAIN_WORD
Similar to HPUX_WORD, with the following exceptions: long doubles are only 8 bytes long (treated as doubles) and DOMAIN bit-field mapping is used. Refer to Chapter 2, "Storage and Alignment Comparisons," in the HP C/HP-UX Programmer's Guide for detailed information on Domain bit-fields.
#pragma HP_ALIGN NOPADDING
Causes all structure and union members that are not bit-fields to be packed on a byte boundary. It does not cause crunched data packing, where there are zero bits of padding. It only ensures that there will be no full bytes of padding in the structure or union.
Accessing Data with the HP_ALIGN Pragma
The HP_ALIGN pragma isolates data structures that are not naturally aligned for PA-RISC systems.

References to non-natively aligned data often results in poorer run-time performance than references to natively aligned data. Natively aligned data is often accessed with a single load or store instruction. Non-natively aligned data must be accessed with one or more load and store instructions.

The HP_ALIGN pragma differs from the +ubytes compiler option. When you use the HP_ALIGN pragma, the compiler localizes inefficient code generation to accesses of data declared with structures or unions under the HP_ALIGN pragma. The +ubytes option assumes that all references to pointer objects are misaligned and performs worst case code generation for all loads and stores of dereferenced data.

The HP_ALIGN pragma offers better run-time performance than the +unumber option. However, the HP_ALIGN pragma requires careful pointer assignment and dereferencing. The following example shows how the pragma is often misused, and what can be done to correct the mistake.

#pragma HP_ALIGN HPUX_WORD
 
struct {
   char chardata;
   int intdata;
} stvar;
 
 
 
main()
{
   int *localptr;
   int localint;
   localptr = &stvar.intdata;
   localint = *localptr;   /* invalid dereference */
}
The above program aborts at run-time when localptr is dereferenced. The structure stvar is declared under the HP_ALIGN HPUX_WORD pragma. Its members will not be natively aligned for PA-RISC. The member stvar.intdata is aligned on a two byte boundary.

The error occurs after the address of stvar.intdata is assigned to localptr. localptr is not affected by the HP_ALIGN HPUX_WORD pragma. When localptr is used to access the data, it is treated as a pointer to four-byte aligned data rather than as a pointer to two-byte aligned data and a run-time error can occur.

Two solutions help to work around this problem. First, the recommended solution is to access non-natively aligned data through structures or unions that are declared under the HP_ALIGN pragma.

For example, the above program can be transformed to:

#pragma HP_ALIGN HPUX_WORD
 
struct {
    char chardata;
    int intdata;
} stvar;   /* stvar is declared under the HP_ALIGN pragma */
 
 
 
main()
{
   int *localptr;
   int localint;
   localint = stvar.intdata; /* Valid access of non-naturally */
                             /* aligned data through a struct */
}
The second method is to inform the compiler that all access of data must assume potentially non-natural alignment. In the case of #pragma HP_ALIGN HPUX_WORD shown in the first example above, you can use the +u2 command line option. This causes all loads and stores of any data to be performed in increments of no greater than 2-bytes at a time.

For complete details about the +ubytes option, see Table 6: HP C Compiler Option Details .

PACK Pragma

#pragma PACK n
The PACK pragma is a simple, intuitive way for users to specify alignment. In the syntax, n is the byte boundary on which members of structs and unions should be aligned, and can be 1, 2, 4, 8, or 16.

The PACK pragma is not intended to be an "extension" of the HP_ALIGN pragma. It is, instead, a simple and highly portable way of controlling the alignment of aggregates. It has some significant differences with the HP_ALIGN pragma, including uniform bitfield alignment, uniform struct and union alignment, and the lack of PUSH and POP functionality.

For complete details on the use of HP_ALIGN and PACK pragmas, see Chapter 2, "Storage and Alignment Comparisons," in the HP C/HP-UX Programmer's Guide.

HP_OPT_DATA Pragma

#pragma HP_OPT_DATA argument
This pragma is used to explicitly specify memory locations that can be prefetched from memory into the cache. This pragma can take only one address as an argument. The argument should have 'register' storage class.

Example:

register int *pi;
#pragma HP_OPT_DATA pi

Listing Pragmas


LINES Pragma

#pragma LINES linenum
Sets the number of lines per page to linenum. The default is 63. The minimum number of lines per page is 20.

WIDTH Pragma

#pragma WIDTH pagewidth
Sets the width of the page to pagewidth. The default is 80 columns. The minimum number of columns per page is 50. Place the WIDTH pragma before any TITLE or SUBTITLE pragmas. The width of the title and subtitle fields varies with the page width.

TITLE Pragma

#pragma TITLE "string"
Makes string the title of the listing. String can have a length of up to 44 characters less than the page width (additional characters are truncated with no warning). The default is no title.

SUBTITLE Pragma

#pragma SUBTITLE "string"
Makes string the subtitle of the listing. String can have a length of up to 44 characters less than the page width (additional characters are truncated with no warning). 8The default is no subtitle.

PAGE Pragma

#pragma PAGE
Causes a page break and begins a new page.

LIST Pragma

#pragma LIST { ON }
#pragma LIST { OFF }
Turns listing functionality ON or OFF when used with the -Wc,-L command line option. The default is ON. Use this pragma to exclude source lines you do not need to list such as include files.

AUTOPAGE Pragma

#pragma AUTOPAGE { ON }
#pragma AUTOPAGE { OFF }
ON causes a page break after each function definition. If the pragma is declared without specifying either the ON or OFF option, then page breaks are generated. If the pragma is not used then no page breaks are generated.

Optimization Pragmas

For additional information on the following optimization pragmas see Optimizing HP C Programs and Threads and Parallel Processing.

ALLOCS_NEW_MEMORY Pragma

#pragma ALLOCS_NEW_MEMORY functionname1,...,functionnamen
States that the function functionname returns a pointer to new memory that it allocates or a routine that it calls allocates. This pragma provides additional information to the optimizer which results in more efficient code.

FLOAT_TRAPS_ON Pragma

#pragma FLOAT_TRAPS_ON { functionname,...functionname }
#pragma FLOAT_TRAPS_ON {_ALL }
Informs the compiler that you may have enabled floating-point trap handling. When the compiler is so informed, it will not perform loop invariant code motion (LICM) on floating-point operations in the functions named in the pragma. This pragma is required for proper code generation when floating-point traps are enabled and the code is optimized.

The _ALL parameter specifies that loop invariant code motion should be disabled for all functions within the compilation unit.

[NO]INLINE Pragma

#pragma INLINE [functionname1,...,functionnamen]
 
#pragma NOINLINE [functionname1,...,functionnamen]
Enables (or disables) inlining of functions. If particular functions are specified with the pragma, they are enabled (or disabled) for inlining. If no functions are specified with the pragmas, all functions are enabled (or disabled) for inlining. Refer to the HP C/HP-UX Programmer's Guide for details and examples.

[NO]PTRS_STRONGLY_TYPED Pragma

#pragma PTRS_STRONGLY_TYPED BEGIN
 
#pragma PTRS_STRONGLY_TYPED END
 
#pragma NOPTRS_STRONGLY_TYPED BEGIN
 
#pragma NOPTRS_STRONGLY_TYPED END
Specifies when a subset of types are type-safe, providing a finer level of control that +O[no]ptrs_strongly_typed. The pragma will take precedence over the command line option, although sometimes both are required. Refer to the HP C/HP-UX Programmer's Guide for details and examples.

NO_SIDE_EFFECTS Pragma

#pragma NO_SIDE_EFFECTS functionname1,...,functionnamen
States that functionname and all the functions that functionname calls will not modify any of a program's local or global variables. This pragma provides additional information to the optimizer which results in more efficient code. See the HP C/HP-UX Programmer's Guide for further information.

Shared Library Pragma

This section describes a pragma for shared libraries. For detailed information on shared libraries, see the HP-UX Linker and Libraries Online User Guide.

HP_SHLIB_VERSION Pragma

#pragma HP_SHLIB_VERSION "mm/[yy]yy"
Assigns a version number to a shared library module. This enables you to store multiple versions of a subroutine in a shared library.

The version number is specified by mm/[yy]yy. mm represents the month, and must be from 1 to 12. [yy]yy represents the year, either in 2 digits or 4 digits. If the 2 digit form is used, it must be from 90 to 99, and will be interpreted as 1990 to 1999. The 4 digit form must be from 1990 to 7450.

This pragma provides a way to guard against unexpected side effects when a shared library is updated. You can put multiple versions of a routine in the library and ensure that programs use the correct version. The date in the SHLIB_VERSION pragma provides the version number. Programs call the version in the shared library with a date less than or equal to the date the program was linked.

The version number should only be incremented when changes made to a subroutine make the new version of the subroutine incompatible with previous versions.

FastCall Pragmas

The compiler pragmas described in this section are designed to speed-up shared library calls. For more information about how these pragmas help shared library performance, see Improving Shared Library Performance.

HP_DEFINED_EXTERNAL Pragma

#pragma HP_DEFINED_EXTERNAL sym1, sym2, ...
The externally defined symbol pragma specifies that the designated symbols are imported from another load module (program file or shared library). Note that this pragma currently works in 32-bit mode only. For 64-bit mode, see the option +Oextern.

HP_LONG_RETURN Pragma

#pragma HP_LONG_RETURN func1, func2, ...
The long return sequence pragma specifies that the named procedures can return directly across a space, without needing to return through an export stub. The main goal of this pragma is to eliminate export stubs, and better enable inlining of import stubs and $$dyncall functionality for indirect calls.

HP_NO_RELOCATION Pragma

#pragma HP_NO_RELOCATION func1, func2, ...
The no parameter/return relocation pragma is used to suppress unnecessary floating point argument relocation. When used, the burden is on the caller and callee to have their argument and their return values agree in which register files they are passed.

Gather/Scatter Prefetch Pragma

This pragma prefetch the cache lines specified in the pragma.
#pragma prefetch <argument>
The behavior of this pragma is as similar as HP_OPT_DATA pragma which just prefetches the data specified. But the prefetch pragma can access cache lines that are accessed via a vector of indices.


NOTE  The argument, can have only one argument per pragma and the argument must be an array element (ex: a[i]). 

Compiler generates instructions to prefetch the cache lines starting from the address of the argument. The caveat is that the values prefetched must be valid values. Reading off the end of an array may result in undefined behavior during runtime.

Example:

The function below will prefetch ia and b, but not a[ia[i]] when compiled with +O2 +Odataprefetch +DA2.0 (or +DA2.0W).
testprefc2(int n, double *a, int *ia, double *b)
{
  for (int i=0; i < n; i++) {
       b[i] = a[ia[i]];
  }
}
Recoding this routine as
#define USER_SPECIFIED 30
testprefc2(int n, double *a, int *ia, double *b)
{
  int dist = (int)USER_SPECIFIED;
  int nend = max(0,n-dist); /* so as not to read past the end of ia */
   for (i = 0; i < nend; i++) /* original loop is for (i = 0; i < n; i++) */
   {
     #pragma prefetch ia[i+4*dist]
     #pragma prefetch a[ia[i+dist]]
     b[i] = a[ia[i]];
   }
/* finish up last part with no prefetching */ 
   for (int i = nend; i < n; i++)
   b[i] = a[ia[i]];
}
allows a[ia[i]] to be prefetched. Note that the compiler continues to unroll the loops as in the original code.

Running HP C Programs

After a program is successfully linked, it is in executable form. To run the program, enter the executable filename (either a.out or the name following the -o option).