Previous | Contents | Index |
The following cxx command options control the action of the preprocessing phase:
Environment Variables
If the environment variable COMP_HOST_ROOT is set, the value is used as the root directory for all stage names rather than the default slash (/). If the environment variable COMP_TARGET_ROOT is set, the value is used as the root directory for all include and library names rather than the default slash (/). COMP_TARGET_ROOT affects the standard directory for include files, /usr/include, and the standard library, /usr/lib/libc.a. If COMP_TARGET_ROOT is set, COMP_TARGET_ROOT/usr/lib is the only directory that is searched for libraries using the -lx option.
If the environment variable TMPDIR is set, the value is used as the directory to hold any temporary files rather than the default /tmp directory.
If the environment variable RLS_ID_OBJECT is set and a link occurs, the value is used as the name of an object to link. The RLS_ID_OBJECT environment variable is always the last object specified to the linker.
Examples
% cxx -g -DUSE_CONCENTRATOR -o netmud netmud.cxx |
This example creates an executable file named netmud with symbol table information for full symbolic debugging (-g). The -D option defines the macro name USE_CONCENTRATOR for the preprocessor.
% cxx -o gfview -I/usr/kafka/src:/usr/barnes/include gfview.cxx |
This command line creates an executable file from the gfview.cxx source file. The -o option names the output file gfview. The -I option directs the preprocessing phase to search the specified directories for include files not found in the current working directory.
% cxx -c io_module.cxx |
This example preprocesses and compiles the source file io_module.cxx and produces an object file named io_module.o. Processing stops after creating the object file.
% cxx -o newsreader io_module.o ui.cxx -L/users/dave -lnews |
This example creates an executable file and the -o option names the file newsreader. The source file ui.cxx is preprocessed and compiled and then linked with the object file io_module.o. The link operation uses the library specified by -l (libnews.a). The linker first looks for the library in the current working directory, then in the directory specified by -L (/users/dave), and finally in $PATH.
% cxx -pg a.cxx b.cxx -no_pg c.cxx |
This command line enables gprof profiling for files a.cxx and b.cxx and disables profiling for file c.cxx.
% cxx one.cxx -x cxx two.c -x none three.c |
This example causes files one.cxx and two.c to be compiled as C++ source files, and file three.c to be compiled as a C source file.
Diagnostics
The cxx compiler generates diagnostic and error messages. The line number and file name where the source code that triggered the message resides are printed along with the diagnostic.
Files
filename.cxx | C++ source code input file |
filename.o | Object file |
a.out | Default output file |
/usr/include
/usr/include/cxx |
Standard directories for include files |
DEC C++ uses cc to invoke the ld linker to generate code. Always use the cxx command to invoke the linker.
Linking through the cxx command ensures that all the necessary link options are passed to the ld linker. If your DEC C++ program is not linked properly, some static objects will not be initialized at program startup.
If you choose to use the
ld
linker directly, you may need to modify your
ld
command whenever you install a new version of the DEC C++ compiler or
the DIGITAL UNIX operating system. After doing such an installation,
you should invoke the cxx command and
specify the -v option to display the
ld
command in use. Then, compare this
ld
command with your
ld
command and make any necessary changes. See Section 1.1, and the cxx(1) and the ld(1) reference pages for more information.
1.3 Name Demangling
The C++ compiler encodes type information in function names to enable type-safe linkage. This encoding is called name mangling.
It is often difficult to decipher mangled names that may appear in diagnostic messages from system tools such as the ld linker. A name demangler is provided to translate such mangled names into the function names that appear in the source code, so that they are recognizable by the user. You can use either the cxx command or the demangle command to help interpret mangled messages from the linker. If you use the cxx command to invoke the linker, DEC C++ pipes any linker output to the name demangler unless you specify the -nodemangle option.
The demangle command reads each file in sequence, demangles any names encoded by DEC C++, and displays the results on the standard output device. See the demangle(1) reference page for more information.
Syntax
demangle [-show_mangled_name][-no_vtable_info][-][file...] |
If no input file is given, or if a minus sign is encountered as an argument (for example, demangle -), the demangle command reads from the standard input file. The demangle utility supports the processing of 8-bit characters.
Options
- | Read from the standard input file. |
-show_mangled_name | Display encoded name in parentheses after demangled name. |
-no_vtable_info | Suppress the display of information concerning internal symbols (specifically __vtbl and __btbl ). |
Examples
demangle file |
This command demangles a file containing DEC C++ encoded names.
ld main.o foo.o |& demangle |
This command (from the C shell) demangles the output from the linker
(ld) when linking the main.o and foo.o
files.
1.4 DEC C++ Class Library
Reusing code is a cornerstone of object-oriented programming. To minimize the time it takes to develop new applications, a set of reusable classes is an essential part of DEC C++. Class libraries offer a variety of predefined classes that enable you to work more efficiently. See the DEC C++ Class Library Reference Manual for a detailed explanation of the class library packages supplied with DEC C++.
Linking to the DEC C++ Class Library
Most of the DEC C++ Class Library packages are automatically included in your program when needed. However, when using the complex package, you must provide the following explicit information for the linker:
-lcomplex -lm |
To use the task package, specify the following when linking using the cxx command:
-threads -ltask |
For example:
cxx thread_program.cxx -threads -ltask |
These and other DEC C++ Class Library packages are documented in the
DEC C++ Class Library Reference Manual.
1.5 Debugging
The Ladebug Debugger is a source-level debugger developed to support DEC C++. The dbx debugger does not support debugging C++ programs. For details on using the Ladebug Debugger, see Chapter 8.
This chapter discusses the features and characteristics specific to the
DEC C++ implementation, including pragmas, predefined names, numerical
limits, and other implementation-dependent aspects of the language
definition.
The DEC C++ compiler implements the language definition as specified in
The Annotated C++ Reference Manual, which is the basis of the currently proposed ANSI C++
standard. This section describes specific accommodations to make
programs developed using other C++ products compile more easily under
DEC C++.
To enhance compatibility with other C++ compilers, DEC C++ supports
options that direct the compiler to interpret the source program
according to certain rules followed by other implementations. The
currently supported options are:
2.1 Compatibility with Other C++ Compilers
Although these options direct the DEC C++ compiler to interpret your
source code according to conventions used by other C++ implementations,
the compatibility with these implementations is not complete. The
following sections describe the compatibility situations that DEC C++
recognizes.
For clarity, these sections are marked to indicate which compatibility
option supports the change in interpretation:
-cfront
or
-ms
.
2.1.1 Incomplete friend Declaration (cfront and ms)
Allow the reserved word class, struct, or union to be omitted from a friend statement (contrary to the syntax rules for C++).
For example:
class foo; class goo { friend foo; //"class" is missing; compatibility options allow this }; |
Ignore any extra comma at the end of the last enumerator in an enumeration declaration.
For example:
enum E {a, b, c,}; // Ignore the "," after "c", if -cfront or -ms is specified |
When a class type declaration is left incomplete at the end of a local scope, the incomplete type declaration is hoisted to its outer scope to allow the type to be completed by any subsequent declaration.
For example:
void bar(struct foo *f); // foo is incomplete at the end of the prototype scope, // so hoist it out to the file scope. struct foo { int i; }; // Now, foo can be completed by this declaration. void bar(struct foo *f) // Now, this foo is the same as the one above. { f->i = 1; } void main (void) { foo r; r.i = 2; bar(&r); // Now, type of r is the same as type of f in bar. } |
Another example:
typedef struct st { struct test *ptr; // test is left incomplete at the end of the scope, // so hoist it out to the file scope. } st; typedef struct test { // Now, test is allowed to be completed. int a; } test; void init_st (st *o) { o->ptr->a = 3; // Now, the ptr field is considered to be the same // type as test just above. } void main (void) { st r; test t; r.ptr = &t; t.a = 1; init_st(&r); } |
When performing overloading resolution, prefer conversion of an enum type object of 0 value to an arithmetic type, to conversion to a pointer type.
For example:
void trans(unsigned int input); // The first trans void trans(char* re); // The second trans enum inputs{nickle, dime}; void f(void) { trans(nickle); // nickle's value is 0, so cfront prefers the first trans } |
When no operator++(int) (or operator--(int)) are visible, then invoke operator++() (or operator--()) for postfix increment (or postfix decrement) operations.
The language specifies that the prefix increment and decrement user-defined operators take one argument (the implicit this argument for a member function), whereas the postfix version takes two arguments (an extra int argument).
For example:
class foo { public: int operator++(); // int operator++(int); int operator--(); // int operator--(int); }; void f(void) { foo j; j++; ++j; j--; --j; } |
When -cfront is specified, the j++ and ++j operations both call int operator++(). Also, the j-- and --j operations call int operator--(). But, if you uncomment int operator++(int) and int operator--(int) in the class declaration, then the language-specified operations will be called whether -cfront is specified or not.
Previous | Next | Contents | Index |