NOTE: See the Optimizing HP C Programs
section of the HP C Online Help for a more detailed description of HP compiler
optimization options.
Compiling HP C Programs
Controlling Code Scheduling
Using Pragmas
Running HP C Programs
Compiling HP C Programs
This section describes the following aspects of compiling an HP C program:
cc [options] files
where:
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.
-optionname [optionarg]where:
cc demo.cthe 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
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
| Option | Description |
|---|---|
| -Aa | Enables strict ANSI C compliance. |
| -Ac | Disables ANSI C compliance (HP C version 3.1 compatibility). |
| -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. |
| -b | Cause the linker ld(1) to create a shared library rather than a normal executable file. |
The following new -B options are recognized by
HP C to specify whether references to global symbols may be resolved
to symbols defined in the current translation unit, or assumed to be
resolved to symbols defined in another load module.
|
|
| -c | Compiles only, does not link. Force an object (.o) file to be produced for each .c file even if only one program is compiled. |
| -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 | Produce dynamically-bound executables. |
| -eepsym | Sets the default entry point address for the output file to be the same as the symbol epsym. |
| -exec | Indicates that any object files created will be used to create an executable file. |
| -E | Performs preprocessing only named C or assembly files, with output to stdout. |
| -fast | Select a combination of compilation options for typically used for optimum execution time. The compiler options expanded when using -fast are: +O2 +Olibcalls +Onolimit +Ofltacc=relaxed +FPD +DSnative +Oshortdata. This option is the same as the +Ofast optimization option. |
| -fpeval= [precision|float|float80] | Specify the minimum precision to use for floating point expression evaluation. Valid values are float, double, and extended. |
| -[no]fpwidetypes | Enable extended and quad floating point data types. |
| -g | Cause the compiler to generate additional information needed by the symbolic debugger. |
| -G | Inserts information required by the gprof profiler in the object file. |
| -Idir | Inserts dir in the include file search path. |
| -lx | Links with the /lib/libx.a and /usr/lib/libx.a libraries. |
| -Ldir | Change the algorithm used by the linker to search for libx.so or libx.a. |
| -minshared | Indicates that the result of the current compilation is going into an executable file that will make minimal use of shared libraries. |
| -n | Cause the output file from the linker to be marked as shareable. |
| -N | Cause the output file from the linker to be marked as unshareable. |
| -o outfile | Rename the output file.. |
| -O | Optimize code at optimization level 2. |
| -P | Perform preprocessing only on the named C files and leave the resultvon corresponding files suffixed .i. |
| -q | Mark the executable as demand-loadable. |
| -Q | Mark the executable as not being demand-loadable. |
| -r | Retain relocation information in the output file for subsequent re-linking. |
| -s | Strip the symbol table from the executable file. |
| -S | Generate an assembly language source file. |
| -t x,name | Substitute subprocess x with name where x is one or more of a set of identifiers indicating the subprocess(es). |
| -Uname | Remove any initial definition of name in the preprocessor. |
| -v | Enable verbose mode. |
| -V | Cause each invoked subprocess to print its version information to stdout (stderr). |
| -w | Suppress warning messages. |
| -Wx, arg1 [,arg2,..,argn] | Passes the arguments arg1 through argn to the subprocess x. |
| -Wd,-a | When processing files which have been written in assembly language, does not assemble with the prefix file which sets up the space and subspace structure required by the linker. |
| -Wx,arglist | Pass the comma-separated argument[s] in arglist to subprocess x. |
| -Y | Enable multi-byte characters inside string literals and comments. This is known as Native Language Support (NLS). |
| -z | Do not bind anything to address zero, i.e., do not allow dereferencing of null pointers at run-time. |
| -Z | Allow dereferencing of null pointers at run-time. |
| +DDdata_model | Generate 32-bit or 64-code. |
| +df name | Specify a profile database file name to be used for profile-based optimizations. |
| +DSmodel | Use the instruction scheduler tuned to the specified model. |
| +e | Enable 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 the $ character in identifier names. |
| +f | Inhibit the promotion of float to double, except for function calls and returns. |
| +FP flags | Specify how the run-time environment for floating-point operations should be initialized at program start up. |
| +help | Launch a web browser displaying the HP C/HP-UX online help. |
| +I | Instrument the application for profile-based optimization (PBO). |
| +ild | Specify incremental linking. |
| +ildrelink | Perform an initial incremental link, regardless of the output load module. |
| +L | Enable any #pragma listing directives and the listing facility. |
| +M level | Provide ANSI, platform and data model migration warnings. |
| +O level | Invoke optimization levels where level is optimization levels 0 to 4. See Optimizing HP C Programs for a description of HP C optimizations. |
| +[no]objdebug | When used with -g, +objdebug leaves debug information in the object files instead of copying it to the executable file (a.out). The object files must be accessible to the HP WDB debugger when debugging. |
| +opts filename | Process options contained in the file as if they were specified on the command line. |
| +P | Optimize the application based on profile data found in the database file flow.data, which is produced by compilation with the +I option. |
| +r | Inhibit the automatic promotion of float to double when evaluating expressions and passing arguments. |
| +[no]srcpos | Control the generation of source position information for the Caliper and CXperf performance analysis tools. |
| +uc | Make unqualified char data types unsigned. |
| +wn | Specify warning message levels where n is 1 - 3. |
| +We arg1[,arg2,...argn] | Selectively interpret any specified warning or future error messages as errors. |
| +Ww arg1[,arg2,...argn] | Selectively treats compiler warnings as warnings. |
Table 7: HP C Compiler Option Details describes
in detail the options that HP C workstations and servers support.
| Option | What It Does | |
|---|---|---|
| -Aa | Requests a compilation in ANSI C mode, based on
the ANSI programming language C standard ISO 9899:1990.
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 your use.
HP C in ANSI mode conforms to these restrictions.
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_SOURCEor define this macro by using the -D name option: cc -D _POSIX_SOURCE myfile.cTo 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_SOURCEor define the macro on the command line: cc -D _XOPEN_SOURCE myfile.cTo 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_SOURCEor 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. | |
| -b | Cause the linker ld(1) to create a shared library rather than a normal executable file. Object files processed with this option must contain position independent code (PIC). -b has no effect on the -E, -P, and -S options. | |
| The following new -B options are recognized by
HP C to specify whether references to global symbols may be resolved
to symbols defined in the current translation unit, or whether they
must by assumed to be resolved to symbols defined in
another load module.
All -B options are applied in a 'left to right' order so that options at the end of a string may supercede those that appear earlier in the string.
| ||
| -c | Compile one or more source files but do not link. 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. Overrides the -r and -b options. Is overridden by the -E, -P, and -S options. | |
| -C | Prevent the preprocessor from stripping comments. See the description of cpp(1) in the HP-UX Reference Manual or the cpp(1) manpage for details. | |
| -Dname -Dname=def | Define 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 | Produce dynamically-bound executables. These support shared libraries and use the features of the dynamic loader. Theshl_load and dlopen APIs are fully supported. The linker links in shared libraries first and then archive libraries. See -minshared for instructions on how to produce statically-bound executables. HP C's default behavior is -dynamic. | |
| -E | Run only cpp on the named C or assembly files, and send the result, including the full path name of the include, to the standard output. Overrides the -b, -c, -o, -r, and -S options. | |
| -eepsym | Set the default entry point address for the output file to be that of the symbol epsym. This option only applies to executable files. It does not work if epsym=xec. | |
| -exec | Indicate that any object files created will be used to create an executable file. Constants with a protected or hidden export class are placed in the read-only data section. This option also implies -Bprotected_def. | |
| -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 other C
compiler applications to HP-UX.
-fast expands to the following HP C/ANSI C options: +O2 +Olibcalls +Onolimit +Ofltacc=relaxed +FPD +DSnative +Oshortdata NOTE: Do not use this option for programs that depend on IEEE standard floating-point denormalized numbers. Otherwise, different numerical results may occur.
|
|
| -fpeval=[float|double|extended] | Specify the minimum precision to use for floating point
expression evaluation. Does not affect the precision
of parameters, return types, or assignments, and does not
impact the floating point constant type or floating
point expression type.
Values for -fpeval include:
|
|
| -[no]fpwidetypes | Enable extended and quad floating point data types. quad is a synonym for longdouble. Without this option, the user still has the longdouble type and all of the functions for longdouble. The default is -nofpwidetypes. | |
| -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:
|
|
| -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. | |
| -lx | Cause 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 | Cause 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 -lbarCompiles 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. |
|
| -minshared | Indicates that the result of the current compilation is going into an executable file that will make minimal use of shared libraries. Equivalent to -exec and -Bprotected. | |
| -n | Cause 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 | Cause 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. | |
| -ooutfile | Cause 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 | Invoke the optimizer to perform level 2 optimization. Other optimization levels can be set. Refer to a summary of major HP C optimization options for details on HP C optimization levels. | |
| -P | Only perform preprocessing. 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 | Cause 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 | Cause 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 | Strip 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 | Compile the named HP C program and leave the assembly language output in a corresponding file with .s as the suffix. Overrides the -c, -r, and -b options. Is overridden by the -E and -Poptions. | |
| -t x,name | Substitute 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:
|
|
| -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. | |
| -usymbol | Enter symbol as an undefined symbol in ld's symbol table. The resulting unresolved reference is useful for linking a program solely from object files in a library. More than one symbol can be specified, but each must be preceded by -u. | |
| -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. | |
| -Wd,-a | When processing files which have been written in assembly language, does not assemble with the prefix file which sets up the space and subspace structure required by the linker. | |
| -Wx,arglist | Pass the comma-separated argument[s] in arglist to subprocess x. | |
| -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 | Enable any #pragma listing directives and the listing facility.
A straight listing prints the following:
|
|
| -W c,-m | Cause 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 | Cause 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 | Specify the level of the warnings messages. The value of n
can be one of the following:
|
|
| -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, -s, and -S options. The +I option does not affect the default optimization level or the optimization level specified by the -O or +O options. | |
| -Y | Enable 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 | Disallow run-time dereferencing of null pointers. Fatal errors result if null pointers are dereferenced. | |
| -Z | Allow dereferencing of null pointers at run-time. This is the default. The value of a dereferenced null pointer is zero. | |
| +DDdata_model | Generate 32-bit or 64-code.
The default is +DD32. |
|
| +dfname | Specify 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. | |
| +DSmodel | Use the code instruction scheduler tuned to the IPF
specified model. The defined values for model are shown below.
For this release of HP C the default is blended.
|
|
| +e | Enable HP value-added features while compiling in ANSI
C mode, -Aa. This option is ignored with -Ac and
-Ae because these features are already provided.
Features enabled include:
|
|
| +f | Inhibit 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. | |
| +FP flags | Specify 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:
|
|
| +help | Launch a web browser displaying an html version of the HP C/HP-UX online help, and then processes any other arguments. | |
| +I | Instruct 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. Note that this option is incompatible with the -G, +P, and -S options. It is incompatible with the -g option only during runtime. |
|
| +ild | Specify incremental linking. If the output file does not exist, or if it was created without the +ild option, the linker performs an initial incremental link. The output file produced is suitable for subsequent incremental links. The incremental link option is valid for both executable and shared library links. It is not valid for relocatable links, options (or tools) that strip the output module, and certain optimization options. See the ld(1) manpage for more information. | |
| +ildrelink | Perform an initial incremental link, regardless of the output load module. In certain situations during incremental linking (for example, internal padding space is exhausted), the incremental linker is forced to perform an initial incremental link. The +ildrelink option allows you to avoid such unexpected initial incremental links by periodically rebuilding the output file. | |
| +L | See -W c,-L | |
| +M0 | Cause migration warnings to be emitted.
Defined values for level are:
| |
| +[no]objdebug | This option, when used with any of the -g options, will
cause the debug information to be left in the object
files instead of being placed in the a.out. Available
only for wdb(1) or gdb(1). +objdebug is the default.
+noobjdebug can be used at link time to place the debug
info into the a.out, even if some objects were compiled
with +objdebug.
NOTE: Object files and archive libraries must be accessible to the debugger if the +objdebug method of storing debug information is used. . |
|
| +Oopt | Invokes the level of optimization selected by opt. opt
can have any of the following values.
These can be preceded by either +O or -O . Defined values for level
are:
NOTE: +Oprocelim is the general default at all levels, unless the users says +ild +ildrelink or -b. NOTE: +O4 is only supported with +P. Otherwise, attempts to activate +O4 will cause the compiler to automatically drop to +O3. |
|
| +opts filename | Process options contained in the file as if they were specified on the command line at the point of the +opts option. | |
| +P | 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 application is optimized based on profile data found in
the database file flow.data, produced by compilation
with +I. +P is equivalent to +Oprofile=use or
+Oprofile=use:filename.
The actual code generation is done at link time. This 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, and -S options. Also refer to the +I, and +df command line options. |
|
| +r | Inhibit the automatic promotion of float to double when evaluating expressions and passing arguments. This option is ignored and a warning produced if the ANSI mode is in effect (see also +f). | |
| +[no]srcpos | Control the generation of source position information for the Caliper and CXperf performance analysis tools. When +srcpos is in effect (the default), the compiler generates this information. When +nosrcpos is in effect, the compiler does not generate this information, and the compiler will instruct the linker to discard any of this information encountered in object files. | |
| +uc | Make unqualified char data types unsigned. By default, the HP C compiler converts all unqualified char data types to signed. Use this option to help port applications from other C compilers, where the default behavior for unqualified char types is unsigned. Be careful when using this option. Your application may have problems 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:
|
|
| +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. | |
| +We arg1[,arg2,...argn] | Selectively interpret any specified warning or future error messages as errors. arg1 through argn are valid compiler message numbers. | |
| +Ww arg1[,arg2,...argn] | Selectively treats compiler warnings as warning. arg1 through argn are valid compiler message numbers. Conflicts between +W, +Ww and +We are resolved based on their severity. +We is the highest and +W is the lowest. |
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.cis equivalent to
cc -v -g prog.cFor example, the following in C shell notation
setenv CCOPTS "-v | +O1" cc +O2 prog.cis equivalent to
cc -v +O2 prog.c +O1In 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.
setenv TMPDIR altdir
where altdir is the name of the alternative directory for temporary files.
Controlling Code Scheduling
Different implementations of IPF may have vastly
different resource constraints, latencies, and other
scheduling criteria. The optimizing scheduler
can currently schedule for both existing IA-64
implementations, Itanium and McKinley. The
+DS model
option describes the values and results of using
various schedulers on IA-64.
For example, you can schedule code to run best on each of these implementations by using either +DSitanium or +DSmckinley, respectively. However, users may also want to optimize their code once, and have it run reasonably well on both implementations. The default setting, +DSblended, attempts to do this.
In particular, code is scheduled such that floating point code is biased to run best on Itanium, with only moderate degradations on McKinley, and integer (or non-floating point) code is biased to run somewhat better on McKinley. For example, +DSblended will schedule for the longer floating-point latencies from Itanium, since this will minimize the stalls incurred on Itanium. Since floating-point code is often contained within loops which can be "modulo-scheduled", these longer latencies can be tolerated on McKinley, with reasonably small degradations due to additional stages in the modulo-scheduled loops.
To schedule code in the fastest manner possible for your system's IPF implementation, use +DSnative.
As new implementations of IPF are released, additional
targets will be added, and the schedule resulting from
+DSblended will change.
This section introduces the following groups of HP C compiler pragmas:
#pragma STDC CX_LIMITED_RANGE on-off-switchThe STDC CX_LIMITED_RANGE pragma enables limited range mathematical behavior for specific blocks of code. It indicates whether out-of-range floating point values (e.g., NaNs and infinities) may occur and must be preserved.
Toggling the switch on results in faster complex arithmatic sequences, for example.
The default is off.
STDC CX_LIMITED can occur:
If this pragma is used in any other context, it's behavior is undefined.
#pragma STDC FP_CONTRACT on-off-switchSTDC FP_CONTRACT controls optimizations on floating-point code, so that the expected accuracy of floating-point computation is not violated.
By default the only optimizations allowed that change values are floating-point multiply add (fma) instructions. While these instructions may change the resulting value over a two-instruction multiply add sequence, the resulting value is actually more accurate, since it has not been subject to an intermediate rounding.
On IPF systems, the benefit from forming these contractions can be significant. Contractions can be enabled and disabled in different blocks of code using the STDC FP_CONTRACT pragma. The default (either ON or OFF is defined by how this pragma is implemented:
If STDC FP_CONTRACT is used in any other context, it's behavior is undefined.
#pragma STDC FENV_ACCESS on-off-switchSTDC FENV_ACCESS allows you to specify when a program can access the floating-point environment to test flags or run under non-default modes. It also enables any optimizations which might affect behavior under non-default floating point modes (e.g., alternate rounding directions or trap enables) or where floating point exception flags are queried.
Using the STDC FENV_ACCESS pragma prevents dead code elimination of instructions which may raise exceptions; result in longer floating-point-to-integer conversion sequences which explicitely check for out-of-range results; and result in longer floating-point division sequences.
STDC FENV_ACCESS can occur:
If STDC FENV_ACCESS is used in any other context, it's behavior is undefined.
Copyright Notice and Identification Pragmas
The following pragmas can be used to insert informational identification
strings in application code during compilation.
COPYRIGHT Pragma
#pragma COPYRIGHT stringThe COPYRIGHT pragma laces 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 COPYRIGHT_DATE, the current year is used. For example, assuming the year is 2000, the directive #pragma COPYRIGHT "Acme Software" places the following string in the object code:
(C) Copyright Acme Software, 2000. All rights reserved. No part of this program may be photocopied, reproduced, or transmitted without prior written consent of Acme Software.
#pragma COPYRIGHT_DATE stringCOPYRIGHT_DATE pecifies a date string to be used in a copyright notice appearing in an object module.
#pragma LOCALITY stringThe LOCALITY pragma specifies a name to be associated with the linker procedures that should be grouped together at program binding or load time. These are 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 LOCALITY_ALL pragma specifies a name to be associated with the linker
procedures and global variables that should be grouped together at program
binding or load time. These are written to a relocatable
object module. All procedures and global variables
following the LOCALITY_ALL pragma are associated
with the name specified in string.
VERSIONID Pragma
#pragma VERSIONID stringSpecifies 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.
#pragma HP_ALIGN align_mode [PUSH] #pragma HP_ALIGN POP
The HP_ALIGN pragma must have a global scope (outside of any function, enclosing structure, or union).
#pragma HP_ALIGN POPThis 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 PUSHThis 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.
#pragma HP_ALIGN HPUX_WORDResults 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_S500Results in doubles being word aligned. This is the default for the Series 500 computer.
#pragma HP_ALIGN HPUX_NATURALResults 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 NATURALResults 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.
#pragma HP_ALIGN DOMAIN_NATURALSimilar to NATURAL except long doubles are only 8 bytes long (treated as doubles).
#pragma HP_ALIGN DOMAIN_WORDSimilar to HPUX_WORD, with the following exceptions: long doubles are only 8 bytes long (treated as doubles) and DOMAIN bit-field mapping is used.
#pragma HP_ALIGN NOPADDINGCauses 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.
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. 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 nThe 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.
FastCall Pragmas
The compiler pragmas described in this section are designed to speed-up
shared library calls.
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). This pragma achieves the same effect as the optimization option +Oextern.
#pragma INIT stringUse 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 ... }
#pragma FINI stringUse 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 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.
#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.
#pragma LINES linenumSets the number of lines per page to linenum. The default is 63. The minimum number of lines per page is 20.
#pragma LIST { ON }
#pragma LIST { OFF }
The LIST pragma 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.
#pragma MSTATSThe MSTATS pragma provides statistical information on the amount of memory used during a compilation. This pragma takes no arguments so there is no way to specify where in your application memory should be calculated.
#pragma PAGECauses a page break and begins a new page.
#pragma SIGNAL intThe SIGNAL pragma allows you to specify a signal identifier to be sent to the compiler during compilation. Signal IDs (such as a Signal 11) can be specified through the use of int.
Once the signal has been received, the signal function would
typically interpret
the signal based upon how it is defined (i.e., abort termination, invalid
function range, termination request sent to program, etc.).
SUBTITLE Pragma
#pragma SUBTITLE stringSUBTITLE 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). The default is no subtitle.
#pragma TITLE stringTITLE 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.
#pragma WIDTH pagewidthThe WIDTH pragma 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.
#pragma FLOAT_TRAPS_ON { functionname,...functionname }
#pragma FLOAT_TRAPS_ON {_ALL }
The FLOAT_TRAPS_ON pragma 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.
#pragma IF_CONVERTIF_CONVERT is a block-scoped pragma. It is intended to recommend if-conversion to eliminate all control flow resulting from conditional code within a scope. If-conversion is the process by which the compiler uses predicates to eliminate conditional branches.
By default at +O2 and higher, the compiler uses heuristics to determine when it is beneficial to apply if-conversion to eliminate a conditional branch. This pragma overrides those heuristics and causes the compiler to eliminate all non-loop control flow within the scope of the pragma
You can specify this pragma to facilitate software pipelining of inner loops that contain conditional code, since the compiler can only software pipeline loops that do not contain control flow. When placed within the scope of an inner loop, this pragma will cause the compiler to eliminate all branches except for the loop back branch.
#pragma NO_INLINE [functionname1,...,functionnamen]The No_Inline pragma tells the compiler to list functions that should never be inlined. If particular functions are specified with the pragma, a list is generated for those functions. If no functions are specified with the pragmas, a list is generated for all functions that should not be inlined.
#pragma INLINE_CALLThe [NO]INLINE_CALL pragma requests the compiler to enable (disable) inlining for a particular call site. The pragma takes no arguments, and affects the outermost, leftmost call in the next statement.
#pragma unroll_facgtor nunroll_factor is a block-scoped pragma specifies that the innermost loop should be unrolled n times. By default, the compiler employs heuristics to determine the best unroll factor for an inner loop. However, if you know that a particular unroll factor is best for the given loop, or alternatively, that no unrolling should be applied to the loop, you can use the unroll_factor pragma to communicate this information to the compiler.
A user-specified unroll factor will override the unroll factor computed by the compiler. Specifying n=1 will prevent the compiler from unrolling the loop. Specifiying n=0 will cause the compiler to use its own heuristics to determine the best unroll factor; this is the same as not specifying the pragma. unroll_factor will be ignored if it is placed in a loop other than the innermost loop.
Profile-based optimization (PBO) pragmas correspond to similar command-line options for IPF systems, described in the Optimizing C Programs section of the HP C online help.
The pragmas described in this section allow you to:
#pragma ESTIMATED FREQUENCY fThe ESTIMATED_FREQUENCY pragma is block-scoped and indicates the estimated relative execution frequency of the current block as compared with the block immediately surrounding it. This pragma may be used to calculate the average trip count in the body of a for loop, or to indicate the fraction of time when a then clause is executed.
#pragma FREQUENTLY_CALLED symbol[,symbol]*FREQUENTLY_CALLED specifies that a list of functions are to be assumed to be frequently called within the application. This is independent of +P: the FREQUENTLY_CALLED pragma overrides any dynamically obtained profile information.
#pragma RARELY_CALLED symbol[,symbol]*RARELY_CALLED specifies that a list of functions are to be assumed to be rarely called within the application. This is independent of +P: the RARELY_CALLED pragma overrides any dynamically obtained profile information.
#pragma DEFAULT_BINDING [symbol{,symbol}]
This pragma assigns global symbols to the default export class.
These symbols may be imported or exported outside of the
current load module. HP C will then access tentative
symbols through the linkage table. Any symbol that is not
assigned to another export class through use of another
pragma (or -B option or the deprecated +O[no]extern option)
will have the default export class.
#pragma EXTERN symbol[,symbol]*When using the EXTERN pragma, the named symbols are assigned the extern export class. These symbols may be imported or exported outside of the current load module. The compiler accesses tentative symbols through the linkage table. Any symbol that is not assigned to another export class through use of another symbol binding pragma (or -B option) will be assigned the default export class.
By default, the compiler may bind references to symbols defined in the
same translation unit. The only way to override this default is to use
the EXTERN pragma or the (analogous) -B
general use options. This adds specified symbols to the extern or
undefined list, and removes all other lists. The EXTERN pragma
works the same as the -Bextern
symbol binding option.
NOTE: When specifying a symbol list, all
symbols are affected. Specifying no symbol list affects only
undefined symbols.
#pragma HIDDEN symbol[,symbol]*The HIDDEN pragma adds specified symbols to both hidden and defined or hidden and undefined lists, removing them from all other lists. The named symbols, or--if no symbols are specified--all symbols are assigned the hidden export class. The hidden export class is similar to the protected export class. These symbols will not be pre-empted by symbols from other load modules.
The compiler may bypass thelinkage table for both code and data references and bind them to locally defined code and data symbols. In addition, hidden symbols will not be exported outside the current load module. The linker may eliminate them from a shared library, but in an executable, they remain accessible to the debugger unless the +Oprocelim is specified from the command line.
The HIDDEN pragma works the same as the
-Bhidden
symbol binding option.
NOTE: Using the HIDDEN pragma with no symbol
list implies the usage of the -W1, -aarchive_shared options.
This causes the linker to prefer an archive library to a shared library if one is
available. This can be overriden on the command line by using a
a subsequent -W1, -a option.
#pragma PROTECTED symbol[,symbol]*The PROTECTED pragma specifies symbols that are specified as having a protected export class. This means that the symbols will not be pre-empted by symbols from other load modules. The compiler may then bypass the linkage table for both code and data references and bind them to locally defined code and data symbols.
The PROTECTED pragma works the same as the
-Bprotected
symbol binding option.
NOTE: Specifying PROTECTED with no symbol list implies
the usage of the -W1, -aarchive_shared options. This causes the
linker to prefer an archive library to a shared library if one is
available. This can be overriden on the command line by using a
a subsequent -W1, -a option.
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).