HPlogo HP-UX/HP C Compiler: HP C/HP-UX Reference Manual > Chapter 9 Compiling and Running HP C Programs

Compiling HP C Programs

» 

Technical documentation

Complete book in PDF

 » Table of Contents

When you compile a program, it passes through one or more of the following steps depending upon which command line options you use:

  • Preprocessor: This phase examines all lines beginning with a # and performs the corresponding actions and macro replacements.

  • Compilation Process: This phase takes the output of the preprocessor and generates object code.

  • Optimization: This optional phase optimizes the generated object code.

  • Linking: In this phase, the linker is invoked to produce an executable program. External references in shared and archived libraries are resolved as required. The startup routines in /opt/langtools/lib/crt0.o are copied in, and the C library in /lib/libc.sl or /lib/libc.a is referenced. (By default, shared libraries take precedence over archived libraries if both versions are available. However, if you use the LPATH environment variable, you should make sure that all shared libraries come before any archive library directories. See the HP-UX Linker and Libraries Online User Guide for information on LPATH or on creating and linking with shared libraries.) Object modules are combined into an executable program file.

    If you are referencing 64-bit binaries on the compile-line you must specify the +DD64 option, or the compiler will pass the 32-bit crt0.o to the linker, producing a Mismatched ABI error message from the linker.

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:

options

is one or more compiler options and their arguments, if any. Options can be grouped together under one minus sign.

files

is one or more file names, separated by blanks. Each file is either a source or an object file.

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 9-2 “HP C Compiler Option Details ” in this chapter). 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:

optionname

is the name of a standard compiler option.

optionarg

is the argument to optionname.

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

HP C Compiler Options

Table 9-1 “HP C Compiler Options at a Glance ” summarizes the command line options supported by HP 9000 workstations and servers. See Table 9-2 “HP C Compiler Option Details ” for detailed information about each option.

Table 9-1 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).

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

-BexternPerforms the same operation as +Oextern=sym1,sym2,sym3... except that symbols are loaded from an existing file, instead of specified on the command line.

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

-dynamicEnables linking of PIC objects.

-E

Performs preprocessing only with output to stdout.

-fastExpands 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.

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

-nosharedCreates 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.

+DCapptypeGenerate code for portable or embedded applications.
+DD32Generates 32-bit code for PA1.1 architecture.
+DD64Generates 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.

+DOosnameSets 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.

+ESconstlitIntroduces 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.

+ESnolitDisables +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.

+hugesizeLowers 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.

+M1Provides platform migration warnings for features that may not be supported in future releases.
+M2Provides 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.

+paRequests routine-level profiling with CXperf.
+palRequests 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.

+sbMake bit-fields signed by default in both 32- and 64-bit modes.

+ubytes

Controls pointer alignment where bytes is 1, 2, or 4.

+ucMakes 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.

+Ww n1[,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 9-2 “HP C Compiler Option Details ” describes in detail the options that HP C workstations and servers support.

Table 9-2 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.

-AeRequests 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.
-BexternPerforms 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 thecompiler 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.
-cCompiles 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.

-dynamicThis option produces 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. 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 other vendors' 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 -0, +01, or +02 option. Currently, debugging is supported at optimization levels 2 and below. If you try to use -g with the +03 or +04 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.

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

-nosharedCreates 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 postprocessed 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. Refer to “Location of Files ” for a description of this path.

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

+DCapptypeGenerate 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.
+DD32Generates 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.
+DD64Generates 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.
+dfnameSpecifies 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)

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.

+DSmodelPerforms 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

+ESconstlitIntroduces 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.

+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.

+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 *);
+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

Enable traps on invalid floating-point operations.

v

Disable traps on invalid floating-point operations.

Z

Enable traps on divide by zero. (If your program must conform to the POSIX standard, do not enable this trap.)

z

Disable traps on divide by zero.

O

Enable traps on floating-point overflow.

o

Disable traps on floating-point overflow.

U

Enable traps on floating-point underflow.

u

Disable traps on floating-point underflow.

I

Enable traps on floating-point operations that produce inexact results.

i

Disable traps on floating-point operations that produce inexact results.

 
D

Enable 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

Disable 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. See “HP C Online Help ” for instructions on setting up your environment to view the HP C Online Help.
+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 seperate 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.

+M1Emit warnings for possible problems connected with platform migration.
+M2Emit 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 Chapter 4, "Optimizing HP C Programs," in the HP C/HP-UX Programmer's Guide.

+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 User's Guide on http://www.docs.hp.com.

+pgmname

Specifies a program name to look up in the flow.data file. Used with profile-based optimization and the +P option.
+pgm
name 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.

+sbUse 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. See Chapter 2, "Storage and Alignment Comparisons," in the HP C/HP-UX Programmers Guide for more information.

+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.

+We n1[,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.

+Ww n1[,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

  • cc -Aa prog.c

    requests a strict ANSI C compilation of prog.c.

  • cc -tp,/users/devel/cpp prog.c

    uses /users/devel/cpp as the pathname for the preprocessing phase.

  • cc -tpca,/users/devel/x prog.s

    uses /users/devel/x/cpp for cpp, /users/devel/x/ccom for ccom, and /users/devel/x/as for as; the assembly file prog.s is processed by the specified assembler.

  • cc -Aa prog.c procedure.o -o prog

    compiles and links the file prog.c, creating the executable program file prog. The compiler produces prog.o. The linker ld(1) links prog.o and procedure.o with all of the HP C startup routines in /lib/crt0.o and the library routines from the HP C library /lib/libc.a.

  • cc prog.c -co /users/my/prog.o

    compiles the source file prog.c and places the object file prog.o in /users/my/prog.o.

  • cc -Wp,-H150000 p1.c p2.c p3.c -o p

    compiles the source files in the option -H150000 to the preprocessor cpp to increase the define table size from the default.

  • cc -Wl,-vt *.c -o vmh

    compiles all files in the working directory ending with .c, passes the -vt option to the linker, and causes the resulting program file to be named vmh.

  • cc -vg prog.c

    compiles prog.c, adds debug information, and displays the steps in the compilation process.

  • cc -S prog.c

    compiles the file prog.c into an assembly output file called prog.s.

  • cc -Wc,-R15 prog.c

    compiles prog.c placing no more than the first fifteen declared register variables in each function into registers.

  • cc -Wc,-L,-m,-o prog.c

    compiles prog.c and produces a source listing, local and global identifier maps, and local code offsets on the standard output device.

  • cc -OAa prog.c

    compiles prog.c in ANSI mode and requests level 2 optimization.

  • cc +O1 prog.c

    compiles prog.c and requests level 1 optimization.

  • cc +w1 prog.c -c

    compiles prog.c with low-level warnings emitted and suppresses linking.

  • cc -D BUFFER_SIZE=1024 prog.c

    passes the option -D BUFFER_SIZE=1024 to the preprocessor, setting the value of the macro for the compilation of prog.c.

  • cc -lm prog.c

    compiles prog.c requests the linker to link the library /lib/libm.a with the object file prog.o to create the executable a.out.

  • cc -L/users/devel/lib -lme prog.c

    compiles prog.c and causes the linker to search the directory /users/devel/lib for the library libme.a, before searching in /lib or /usr/lib for it.

  • cc +DA1.1 +Z -c prog.c

    compiles prog.c for use in a large shared library in 32-bit mode.

  • cc +DA2.0W +Z -c prog.c

    compiles prog.c for use in a large shared library or executable in 64-bit mode.

  • cc +DA1.1 +z -c prog.c

    compiles prog.c in 32-bit mode for use in a shared library with less than 16K of symbols.

  • cc +DA2.0W -noshared +Onoextern prog.c

    compiles prog.c in 64-bit mode without shared libraries. (Refer to the discussion on optimization options in the C online help or the HP C/HP-UX Programmer's Guide for information on the +O[no]extern option.)

Environment Variables

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

  • CCOPTS

  • TMPDIR

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.

© Hewlett-Packard Development Company, L.P.