Revision/Update Information: This is a revised manual.
Software Version: DEC C++ Version 5.7 for DIGITAL UNIX
Digital Equipment Corporation
Maynard, Massachusetts
The information in this document is subject to change without notice and should not be construed as a commitment by Digital Equipment Corporation. Digital Equipment Corporation assumes no responsibility for any errors that may appear in this document.
The software described in this document is furnished under a license and may be used or copied only in accordance with the terms of such license.
The following are trademarks of Digital Equipment Corporation: DEC, DEC FUSE, DECthreads, Ladebug, OpenVMS, ULTRIX, VAX, VAX DOCUMENT, VMS, the DEC C++ logo, and the DIGITAL logo.
The following are third-party trademarks:
AT&T is a registered trademark of American Telephone and Telegraph Company.
Hewlett-Packard is a registered tradmark of the Hewlett-Packard Company.
IEEE is a registered trademark of the Institute of Electrical and Electronics Engineers, Inc.
Microsoft is a registered trademark, and Visual C++ is a trademark of Microsoft Corporation.
OSF/1 is a registered tradmark of the Open Software Foundation, Inc.
POSIX is a registered certification mark of the Institute of Electrical and Electronic Engineers.
UNIX is a registered trademark in the United States and other countries,
Portions of the ANSI C++ Standard Library have been implemented using source licensed from and copyrighted by Rogue Wave Software, Inc.
Information pertaining to the C++ Standard Library has been edited and reprinted with permission of, Rogue Wave Software, Inc. All rights reserved.
Portions copyright 1994-1996 Rogue Wave Software, Inc.
ZK6388
This document is available on CD-ROM.
Contents | Index |
This manual contains information for developing and debugging DEC C++ programs on DIGITAL UNIX systems, and includes information on other DIGITAL UNIX features and tools that work with DEC C++.
This manual is intended for experienced programmers who need to develop DEC C++ programs on DIGITAL UNIX systems. Users of this manual should have a basic understanding of the C++ language and some familiarity with the DIGITAL UNIX operating system.
This manual is organized as follows:
The following documents contain information associated with topics in this manual:
The C++ Programming Language, 2nd Edition and the STL Tutorial and Reference Guide are available only in printed form. Online copies are not available.
The following documents are not included in the DEC C++ documentation set. Refer to them for additional information on the C++ programming language, DEC C, or DIGITAL UNIX programming.
Table 1 lists the conventions used in this manual.
Convention | Meaning |
---|---|
% | A percent sign (%) is the default user prompt. |
class complex{
. . . }; |
A vertical ellipsis indicates that some intervening program code or output is not shown. Only the more pertinent material is shown in the example. |
,... | A horizontal ellipsis in a syntax description indicates that you can enter additional parameters, options, or values. A comma preceding the ellipsis indicates that successive items must be separated by commas. |
The
generic
class...
The get() function... |
Monospaced type denotes the names of DEC C++ language elements, and also the names of classes, members, and nonmembers. Monospaced type is also used in text to reference code elements displayed in examples and file-name extensions. |
italic | Italic type denotes the names of variables that appear as parameters or in arguments to functions, and also denotes book titles. |
boldface | Boldface type in text indicates the first instance of terms defined in text. |
UPPERCASE
lowercase |
The DIGITAL UNIX operating system distinquishes between uppercase and lowercase characters. Literal strings that appear in text, examples, syntax descriptions, and function definitions must be entered exactly as shown. |
cxx (1) | Cross-references to reference pages include the appropriate section number in parentheses. |
You may send comments or suggestions regarding this manual, or any DEC C++ document, by electronic mail to the following Internet address:
cxx_docs@bookie.enet.dec.com
If you have access to a FAX machine, you may send your comments or suggestions to:
DEC C++ Documentation, ZKO2-3/K35
603-881-0120
This chapter provides information about the basic steps involved in developing a DEC C++ program on a DIGITAL UNIX system. It explains how to compile, link, and debug DEC C++ programs.
DEC C++ is an implementation of the C++ programming language. The DEC
C++ compiler is part of the DIGITAL UNIX compiler system. See the
DIGITAL UNIX Programmer's Guide for program development
information that applies to all DIGITAL UNIX languages, such as using
the compiler system, creating shared libraries, profiling, and
optimization.
1.1 Compiling a DEC C++ Program
The cxx command invokes the DEC C++ compiler. For a full description of the cxx command, see Using the DEC C++ Compiler in this chapter, or the cxx(1) reference page. For additional information about this release, see the online release notes in:
/usr/lib/cmplrs/cxx/DECCXXnnn.release-notes |
You can compile a mixture of C++ and C source code by entering a single cxx compile command. The DEC C++ compiler distinguishes between C++ source files (for example, .cxx) and C source files (for example, .c) based on their file extensions, and compiles the modules appropriately.
Unless you use the -x option to direct the DEC C++ compiler to ignore file-name extensions, passing a file with a .c extension to the cxx command causes the compiler driver to treat the file as a C file and pass it on to the cc command. If the file contains C++ code instead of C code, the compilation may produce errors.
The cxx command invokes the DEC C++ compiler, and possibly other components of the compiler system, depending on the specified command options and files. When you start the cxx compiler, it normally performs the following tasks:
The cxx command compiles C++ code into machine-readable instructions. The desired output is specified with an option on the command line, and can be object files or symbolic assembly language.
The compiler produces one object file for each file that is compiled. If the linker is called and only one source file was specified on the command line, the single object file is deleted after the linking operation.
Syntax
/usr/bin/cxx [ option ] ...file ... |
An option is an optional list of compile-time options.
A file is one or more file specifications separated by white space.
You cannot group multiple options after a single hyphen; that is, -pg is different than -p -g.
Supply complete relative or absolute path information when the source file is not in your current directory.
Use the -c option to stop compiler operation before linking, which results in one or more output files with the .o extension. Use the -E option to run only the preprocessor.
The detection of an error in one source file does not affect compilation of other source files specified on the same command line.
Unless you use the -x option to direct the DEC C++ compiler to ignore file-name extensions, the compiler recognizes the following extensions as having the special significance noted:
.cxx
.CXX .cpp .CPP .cc .CC .C |
C++ source code. |
.hxx | C++ header file. |
.ixx | C++ source code already processed by the preprocessor. |
.a | Linker library. -x has no effect on files with this extension. |
.c | C source code to be compiled with the DEC C compiler. |
.i | C source code already processed by the preprocessor. |
.o | Linker object module. -x has no effect on files with this extension. |
.so | Shared object (shared library). |
Command options recognized by the cxx compiler are described in the General Options section in this chapter. Some of the options affect the behavior of the preprocessor. The preprocessor is invoked through the cxx command for C++ files, and is not invoked with a separate command. Any options not recognized by the cxx compiler are assumed to be linker options and are passed through to the linker. See the ld(1) reference page for linker options.
Macro Names
The following standard macro names are understood by the preprocessor. These names cannot be redefined or undefined.
__LINE__ | The current line number (a decimal integer). |
__FILE__ | The current file name (a character string). |
__DATE__ | The source file's compilation date (a character string literal of the form "Mmm dd yyyy", where the month names are the same as those generated by the asctime function, and the first character of "dd" is a space character if the value is less than 10). |
__TIME__ | The source file's compilation time (a character string literal of the form "hh:mm:ss", as in the time generated by the asctime function). |
In addition, the following macro names are predefined for DEC C++. These names can be undefined or redefined.
These names are useful in preprocessor #ifdef and #if defined directives to isolate code intended for one of the particular cases. You can use these names anywhere you use other defined names, including within macros.
General Options
The following general options are supported by the cxx command:
none | Do not do any inlining. This is the default when compiling with the -O0 and -O1 optimization level. | |
manual | Inline only those function calls explicitly requested for inlining by an inline keyword. This is the default when compiling with the -O2 and -O3 flags. | |
size | Inline all of the function calls in the manual category, plus any additional calls that the compiler determines would improve run-time performance without significantly increasing the size of the program. This is the default when compiling with -O , -O4 , or -O5 . | |
speed | Inline all of the function calls in the manual category, plus any additional calls that the compiler determines would improve run-time performance, even where it may significantly increase the size of the program. | |
all | Inline every call that can be inlined while still generating correct code. Recursive routines, however, will not cause an infinite loop at compile time. |
For optimization level 0 ( -O0 ), the compiler ignores the -inline option and no inlining is done. | |||||||||||||||||||
-K | Build and use intermediate files, producing a file with the conventional extension for the type of file. These intermediate files are not removed, even when a stage encounters a fatal error. Extensions are appended to the output if it does not already have an extension. | ||||||||||||||||||
-machine_code | List the generated machine code in the listing file. To produce the listing file, you must also specify -source_listing . The default is to not list the generated machine code. | ||||||||||||||||||
-misalign |
Specify that code generated for indirect load and store instructions
should not generate alignment faults for arbitrarily aligned addresses.
Using this option increases the size of generated code and might have a
negative impact on performance.
The default condition is for code generated for indirect load instructions and store instructions to generate alignment faults for arbitrarily aligned addresses. Same as -assume noaligned_objects . |
||||||||||||||||||
-ms | Interpret source programs according to certain language rules followed by Microsoft's Visual C++. This option also defines the macro __MS . | ||||||||||||||||||
-no_misalign | Negate the -misalign option. Same as -assume aligned_objects . | ||||||||||||||||||
-no_pg | Selectively disable profiling for individual modules when using the -pg graph profiling option. | ||||||||||||||||||
-nocleanup |
Disable generation of implicit exception handlers. Procedures without
explicit handlers may have implicit handlers. For example, the compiler
creates a handler for each automatic object that has a destructor. The
compiler also creates handlers for constructors that initialize
subobjects that have destructors. In such a constructor, the compiler
creates a handler for each member with a destructor, and a handler for
each base class with a destructor. The
-nocleanup
option suppresses generation of such implicit handlers, which results
in a slightly smaller executable.
The -nocleanup option lets the compiler do additional optimizations because it is freed from concern with the abnormal transfer of control that occurs when exceptions are raised. Note that this can cause problems in your program if an exception does get raised or if setjmp() and exc_longjmp() are used. This option should not be used in programs that raise exceptions or call setjmp() and exc_longjmp() . |
||||||||||||||||||
-nodemangle | Do not pipe linker messages through the demangler. This causes linker messages to contain mangled names. By default, cxx pipes linker messages through the demangler so that demangled names are displayed. | ||||||||||||||||||
-noinline
or -no_inline |
Do not compile any function calls as inline code. | ||||||||||||||||||
-noinline_auto | Compile only inline functions that are explicitly declared to be inline. | ||||||||||||||||||
-nomember_alignment | Direct the compiler to byte-align data structure members (with the exception of bit-field members). By default, data structure members are aligned on natural boundaries (the next boundary appropriate to the type of the member) rather than the next byte. For example, an int variable member is aligned on the next longword boundary; a short variable member is aligned on the next word boundary. Using any of the #pragma member_alignment , #pragma nomember_alignment , and #pragma pack directives within the source code overrides the setting established by this option. | ||||||||||||||||||
-non_shared | Do not produce a dynamic executable file. The loader uses regular archives to resolve undefined symbols and object files ( .o suffix) from archives included in the executable produced. | ||||||||||||||||||
-noobject | Do not produce an object file. | ||||||||||||||||||
-nopragma_template | Disable all #pragma define_template directives in the source code. This option has no affect on the -define_templates command line option. | ||||||||||||||||||
-nopt | Direct the compiler not to automatically instantiate templates. | ||||||||||||||||||
-o file | Name the final output file, rather than use the default a.out . The given name is used regardless of the type of file (executable, object, assembly, or other type). | ||||||||||||||||||
-O[ n] | Set the level of optimization. Note that different optimizations are performed at each level, depending on whether you invoke the compiler with or without the -migrate option. (The -migrate option is provided for compatibility with older versions of DEC C.) The following table lists the types of optimizations that are performed if the -migrate option is not explicitly specified: | ||||||||||||||||||
|
|||||||||||||||||||
In addition to affecting the generated code, the -O level is passed on to ld and om (if om is specified). | |||||||||||||||||||
The general guidelines for optimization are as follows:
|
|||||||||||||||||||
Other switches that can possibly affect run-time size and speed are as
follows:
|
|||||||||||||||||||
When you use -g for best debugging, optimizations are suppressed. Thus, when comparing the effects of different optimization levels, you should not specify -g or -g2 . For such comparisons, you specify -g0 , which suppresses debugging information. | |||||||||||||||||||
As noted previously, different optimizations are performed at each level, depending on whether you invoke the compiler with or without the -migrate flag. The following table lists the types of optimizations that are performed if -migrate is specified: | |||||||||||||||||||
|
|||||||||||||||||||
The correspondence between optimization levels when -migrate is not specified and when it is specified is as follows: | |||||||||||||||||||
|
|||||||||||||||||||
-om | Perform code optimization after linking, including nop (No Operation) removal, .lita removal, and reallocation of common symbols. This option also positions the global pointer register so the maximum addresses fall in the global pointer-accessible window. The -om option is supported only for programs compiled with the -non_shared option. The following options can be passed directly to -om by using the -WL compiler flag: | ||||||||||||||||||
-WL,-om_compress_lita --- remove unused .lita entries after optimization, and then compress the .lita section. | |||||||||||||||||||
-WL,-om_dead_code --- remove dead code (unreachable instructions) generated after applying optimizations. The .lita section is not compressed by this option. | |||||||||||||||||||
-WL,-om_ireorg_feedback, file --- use the pixie-produced information in file.Counts and file.Addrs to reorganize the instructions to reduce cache thrashing. | |||||||||||||||||||
-WL,-om_no_inst_sched --- turn off instruction scheduling. | |||||||||||||||||||
-WL,-om_no_align_labels --- turn off alignment of labels. Normally, the -om option quadword aligns the targets of all branches to improve loop performance. | |||||||||||||||||||
-WL,-om_Gcommon, num --- set size threshold of "common" symbols. Every "common" symbol whose size is less than or equal to num will be allocated close to each other. This flag can be used to improve the probability that the symbol can be accessed directory from the global pointer register. Normally, the -om option causes the compiler to try to collect all "common" symbols together. | |||||||||||||||||||
-p | Perform profiling by periodically sampling the value of the program counter. This option affects only linking. When linking is done, this option replaces the standard run-time startup routine with the profiling run-time startup routine mcrt0.o and searches the level 1 profiling library libprof1.a . When profiling is completed, the startup routine calls the monstartup routine and produces a mon.out file that contains execution-profiling data for use with the postprocessor prof . Same as -p1 . | ||||||||||||||||||
-p0 | Do not perform profiling. This is the default. | ||||||||||||||||||
-p1 | Same as -p . | ||||||||||||||||||
-pg |
Perform call graph profiling using the
gprof
tool.
For more information on profiling C++ code, see the DIGITAL UNIX Programmer's Guide and the appropriate reference pages. |
||||||||||||||||||
-pt | Direct the compiler to automatically instantiate templates. | ||||||||||||||||||
-pthread | Direct the linker to use the threadsafe version of any library specified with the -l flag when linking programs. This option also tells the linker to include the POSIX 1003.1c-conformant DECthreads interfaces in libpthread when linking the program. | ||||||||||||||||||
-ptr pathname |
Specify a repository,
with
./cxx_repository
as the default. If you specify several repositories, only the first is
writable, and the default repository is ignored unless explicitly named.
Specifying this option at link time enables DEC C++ to recognize and use the various template instantiations within the specified repository. If you use this option, make sure that the repository current at compile time is the same one accessed by the linker at link time. |
||||||||||||||||||
-ptsuf" list" | Specify a list of file-name extensions that are valid for template definition files. | ||||||||||||||||||
-ptv | Turn on verbose or verify mode to display each phase of template instantiation as it occurs. This option is useful as a automatic instantiation learning aid. | ||||||||||||||||||
-r | Retain relocation entries in the output file. Relocation entries must be saved if the output file is to become an input file in a subsequent linker run. This option prevents final definitions from being given to common symbols; it also suppresses the diagnosis of undefined symbols. | ||||||||||||||||||
-readonly_strings | Make all string literals read only. This is the default. | ||||||||||||||||||
-rpath string | Set the rpath to the specified string. This option is meaningful for shared linkage only. | ||||||||||||||||||
-S | Compile the specified source programs and produce symbolic assembly language in corresponding files with a .s extension. Do not assemble these files. If the file name argument already has a .s extension, do nothing at all. | ||||||||||||||||||
-shared | Produce a shared object. This includes creating all of the tables for run-time linking, and resolving references to other specified shared objects. The object created may be used by the linker to make dynamic executables. | ||||||||||||||||||
-show keyword [, keyword,...] | Specify one or more items to be included in the listing file. When specifying multiple keywords, separate them by commas (with no intervening blanks). To use any of the -show keywords, you must also specify the -source_listing option. The -show keywords are as follows: |
all | Enable all options. | |
[no]expansion | Determine whether or not to place final macro expansions in the program listing. When you specify the expansion keyword, the number printed in the margin indicates the maximum depth of macro substitutions that occur on each line. | |
[no]header | Determine whether or not to produce header lines at the top of each page of listing. | |
[no]include | Determine whether or not to place contents of #include files in the program listing. | |
none | Disable all options. | |
[no]statistics | Determine whether or not to place compiler performance statistics in the program listing. | |
[no]source | Determine whether or not to place source program statements in the program listing. |
The default is to show page headers and source; that is:
-show header,source . |
|||||||||
-signed | Cause all char declarations to have the same machine representation and value set as signed char declarations. This is the default. | ||||||||
-source_listing | Produce a source code listing file of the same name as the source file, but with the extension .lis . | ||||||||
-strong_volatile |
Allow byte and word access of data at byte granularity by using a
load-locked instruction sequence for byte and word stores. This means
that, for assignments to objects that are less than or equal to 16 bits
in size and have been declared as volatile, assignments to adjacent
volative small objects by different threads in a multithreaded program
will not cause one of the objects to receive an incorrect value.
The generated code includes a load-locked instruction for the enclosing longword or quadword, an insertion of the new value of the object, and a store-conditional instruction for the enclosing longword or quadword. |
||||||||
-t |
Select a name to use for a particular pass, startup routine, or
standard library, from the set of
-t[fablyzrnL]
,
-h
path
, and
-B
string
flags. These arguments are processed from left to right so
their order is significant. When the compiler encounters the
-B
flag, the selection of names takes place using the last
-h
and
-t
flags. Therefore, the
-B
flag is always required when using
-h
or
-t
. Sets of these flags can be used to select any combination of names.
The -p[01] flags must precede all -B flags because they can affect the location of run times and what run times are used. Use the -t[fablyzrnL] suboptions to select the names. The names selected are those designated by the characters following the -t flag as follows:
|
||||||||
-taso |
Tell the linker that the executable file should be loaded in the lower
31-bit addressable virtual address range. You can also use the
-T
and
-D
options to the
ld
command to ensure that the adresses of text and data segments are
loaded into low memory.
Besides setting default addresses for text and data segments, the -taso option also causes shared libraries linked outside the 31-bit address space to be appropriately relocated by the loader. If you specify -taso and also specify text and data segment addresses with -T and -D , those addresses override the -taso default addresses. The -taso option is useful for porting 32-bit programs to DIGITAL UNIX systems. |
||||||||
-threads | Direct the linker to use the thread-safe version of any library specified with the -l flag when linking programs. This option also tells the linker to include both the DECthread interfaces that are conformant with POSIX 1003.4a Draft 4. The flag is supported only for compatability with earlier releases of the DIGITAL UNIX operating system. New designs should use the -pthread option. | ||||||||
-tune option |
Select processor-specific instruction tuning for implementations of the
operating system architecture. Using
-tune
causes the generated code to run correctly on all implementations of
the architecture. Tuning for a specific implementation may improve
run-time performance; however, code tuned for a specific target may run
slower on another target.
The following options are supported:
|
||||||||
-unroll n | Control loop unrolling done by the optimizer. The integer n signifies the number of times to unroll loop bodies. Specifying 0 for n tells the optimizer to use its own default unroll amount. This is the default. | ||||||||
-unsigned | Cause all char declarations to have the same machine representation and value set as unsigned char declarations. The -unsigned option overrides -signed if both are specified on the command line. | ||||||||
-use_ld_input |
Direct the DEC C++ compiler to record in the writable repository the
names of requested automatic template instantiation object files in a
linker options file.
The DEC C++ compiler then adds the linker options file to the ld command line using the ld -input <file> option. The default behavior is to add the instantiation file names directly to the ld command line. You can use the -use_ld_input option to reduce long ld command lines that cause ld to fail because of Arg list too long errors. This option is supported only on DIGITAL UNIX Version 3.2C and later systems. |
||||||||
-v | Print the names of compiler phases as they execute, along with their arguments and input and output files. This option also prints resource usage in the following format: user time, system time, total elapsed time, percentage use of CPU cycles. | ||||||||
-V | Enable printing of the version of the compiler and its phases. | ||||||||
-varargs | Print warnings for all lines that may require macros contained in the header file varargs.h . | ||||||||
-verbose | Include identifiers with messages the compiler issues in response to #pragma message directives. | ||||||||
-volatile | Compile all variables as volatile . | ||||||||
-vptr_size | Make 64 bits the default size of virtual function and virtual base pointers in a C++ class object (64 bits is the normal default). This option also enables #pragma pointer_size and passes -taso to the linker. | ||||||||
-vptr_size_short | Make 32 bits the default size of virtual function and virtual base pointers in a C++ class object. This option also enables #pragma pointer_size and passes -taso to the linker. | ||||||||
-w | Suppress warning and informational compiler messages, but not back-end messages. Same as -w2 . | ||||||||
-w0 | Display all levels of compiler messages. | ||||||||
-w1 | Suppress informational compiler messages. This is the default. | ||||||||
-w2 | Same as -w . | ||||||||
-W
c[
c...],
arg1[, arg2...] |
Pass the arguments arg2...] to the compiler stages c[ c...]. Use this option to pass arguments through to a particular stage, which otherwise would be consumed by an earlier stage. The c argument selects the compiler stage in the same way as it does in the -H option. Valid characters for c are: a, b, f, l, L, n, r, t, y , and z . | ||||||||
-weak_volatile | Do not generate load-locked instructions for a sequence of byte or word stores for assignments to objects that are less than or equal to 16 bits in size and have been declared as volatile. This allows byte or word access to memory-like I/O devices for which larger access will not cause read or write side effects. Because the sequence does not access byte or word data independently directly in memory (that is, ensure byte granularity), adjacent volatile data can be corrupted when such byte or word accesses are performed in a multithreaded environment (for example, two volative short s stored in a longword and accessed asynchronously). | ||||||||
-writable_strings | Make string literals writeable. | ||||||||
-x cxx | Cause all subsequent file names to be compiled as C++ source files, regardless of their suffixes (except .a and .o). This option applies to all following file names up to the next -x option on the command line. | ||||||||
-x none |
Cause all subsequent file names to be treated according to their file
name suffixes. This option reverses the effect of the
-x cxx
option. It applies to all following file names until the next
-x
option on the command line.
In the following example, files one.cxx and two.c will be compiled
as C++ source files, and file three.c will be compiled as a C source
file:
|
||||||||
-xref
-xref_stdout |
Direct the DEC C++ compiler to generate a data file that the DEC FUSE
Database Manager uses to create a cross-reference database file. This
database file is used by the DEC FUSE C++ Class Browser, Call Graph
Browser, and Cross-Referencer.
Specifying the -xref_stdout option directs the compiler to output the data file to standard output. |
||||||||
-xtaso | Set the default pointer size of the compilation unit to 64 bits (for all pointers except virtual function and virtual base pointers; 64 bits is the normal default). This option enables #pragma pointer_size and passes -taso to the linker. | ||||||||
-xtaso_short | Set the default pointer size of the compilation unit to 32 bits (for all pointers except virtual function and virtual base pointers). This option also enables #pragma pointer_size and passes -taso to the linker. The this pointer is unaffected by this option, it remains the system default pointer size, which is 64 bits. | ||||||||
-Zp n | Align structure members on alignment specified by the integer n, where n can be 1, 2, or 4. This option specifies packing so that each structure member after the first is stored on n-byte boundaries as specified by the flag you choose. When you specify the -Zp option without an n value, structure members are packed on 1-byte boundaries. |
Next | Contents | Index |