DEC C++
Using DEC C++ for DIGITAL UNIX Systems


Previous Contents Index

The following cxx command options control the action of the preprocessing phase:
-cpp Run the preprocessor on the source files before compiling. This is the default. If both -cpp and -nocpp are included on the command line, the option specified last is in effect.
-nocpp Do not run the preprocessor on the source files before compiling. If both -nocpp and -cpp are included on the command line, the option specified last is in effect. If -P or -E is specified, -nocpp has no effect.
-C Prohibit the preprocessor from removing comments in the source file. (Use with the -E or -Em option.)
-D name=def
-D name
Define name to the preprocessor, as if the line #define name def were prepended to the C++ source file. There can be a space between the option and name. If name or def contains a dollar sign ($), they must be surrounded by apostrophes ('). If no =def is specified, the name is defined as 1.
-E Run only the preprocessor on the source files (regardless of whether a suffix exists), and send the result to the standard output. This sets the -cpp option.
-Em Run only the preprocessor on the source files (regardless of whether a suffix exists), and produce makefile dependencies instead of the usual output. For each source file, the preprocessor creates one makefile entry naming the object file and listing all included files as dependencies. Same as -M .
-I Do not search for #include files in the standard directories, /usr/include/cxx and /usr/include . Because -I can be followed by a directory, do not place a nondirectory file name on the command line immediately following -I . If -I is being used without a directory, follow it with another option or place it at the end of the command line to avoid misinterpretation.
-I dir Define the directory name dir to the preprocessor for use in searching for quoted and angle-bracketed include files. There can be a space between the option and dir. The preprocessor searches for include file names that do not begin with a slash (/) in the following order:
  1. Quoted file names:
    1. In the directory containing the source file with the #include directive
    2. In the directories specified by the -I option
    3. In the /usr/include/cxx and /usr/include directories
  2. Angle-bracketed files are searched for in the list of directories specified on the command line, then in the /usr/include/cxx directory, and finally, in the /usr/include directory.

If -nocurrent_include is specified, the preprocessor does not search in the directory containing the source file.

-M Run only the preprocessor on the source files (regardless of whether a suffix exists), and produce makefile dependencies instead of the usual output. For each source file, the preprocessor creates one makefile entry naming the object file and listing all included files as dependencies. Same as -Em .
-MD Produce a dependency file, which has the suffix .d appended to the object file name. This dependency file is created even if the object file is not. The information and the format in the dependency file is identical to that produced by the -M flag. The -MD flag allows dependency information to be generated at the same time that a compilation is occurring.
-nocurrent_include Do not search for quoted include files in the directory containing the source file with the #include line. The preprocessor will still search the directories specified by the -I option and in the standard directory /usr/include . See also the -I dir option.
-oldcomment Remove comments from preprocessor output files and replace those comments with nothing.
-P Run only the preprocessor and put the result for each source file in a corresponding .ixx file, without including line numbers. The -P option has no effect if specified after -E or -Em . If specified before -E , it overrides -E . If specified before -Em , it writes the makefile dependencies to .ixx files.
-U name Cancel any command-line definition of name to the preprocessor, as if the line #undef name were prepended to the C++ source file. There can be a space between the option and name. If name contains a dollar sign ($), name must be surrounded by apostrophes ('). The undefine operation occurs after any definitions produced by the -D options. Symbols defined by default are listed in the Description section.

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

1.2 Linking a DEC C++ Program

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.


Chapter 2
DEC C++ Implementation

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.

2.1 Compatibility with Other C++ Compilers

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:

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 
}; 

2.1.2 Enumerators in an Enumeration Declaration (cfront and ms)

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 

2.1.3 Incomplete Declarations (cfront and ms)

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); 
} 

2.1.4 Overloading Resolution and Enumeration Value of Zero (cfront)

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 
} 

2.1.5 Prefix and Postfix Increment and Decrement Operators (cfront)

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