MAN page from Trustix gcc-c++-2.95.3-1tr.i586.rpm


Section: GNU Tools (1)
Updated: 30apr1993


g++ - GNU project C++ Compiler 


g++ [option | filename ]... 


The C and C++ compilers are integrated;g++is a script to callgcc with options to recognize C++. gccprocesses input filesthrough one or more of four stages: preprocessing, compilation,assembly, and linking. This man page contains full descriptions for onlyC++ specific aspects of the compiler, though it also containssummaries of some general-purpose options. For a fuller explanationof the compiler, seegcc(1).

C++ source files use one of the suffixes `.C', `.cc', `.cxx', `.cpp', or `.c++'; preprocessed C++ files use the suffix `.ii'. 


There are many command-line options, including options to controldetails of optimization, warnings, and code generation, which arecommon to both gccandg++. For full information on all options, see gcc(1).

Options must be separate: `-dr' is quite different from `-d -r'.

Most `-f' and `-W' options have two contrary forms: -fnameand-fno-name (or -Wnameand-Wno-name). Only the non-default forms are shown here.

Compile or assemble the source files, but do not link. The compileroutput is an object file corresponding to each source file.
Define macro macro with the string `1' as its definition.
Define macro macro as defn.
Stop after the preprocessing stage; do not run the compiler proper. Theoutput is preprocessed source code, which is sent to thestandard output.
Treat all possible member functions as virtual, implicitly. Allmember functions (except for constructor functions andnewordeletemember operators) are treated as virtual functions of the class wherethey appear.

This does not mean that all calls to these member functions will bemade through the internal table of virtual functions. Under somecircumstances, the compiler can determine that a call to a givenvirtual function can be made directly; in these cases the calls aredirect in any case.

Permit the use of `$' in identifiers.Traditional C allowed the character `$' to form part of identifiers; by default, GNU C alsoallows this. However, ANSI C forbids `$' in identifiers, and GNU C++ also forbids it by default on mostplatforms (though on some platforms it's enabled by default for GNUC++ as well).
Use this option to instruct the compiler to be smarter about when it canelide constructors. Without this flag, GNU C++ and cfront bothgenerate effectively the same code for:

A foo ();
A x (foo ());   // x initialized by `foo ()', no ctor called
A y = foo ();   // call to `foo ()' heads to temporary,
                // y is initialized from the temporary.

Note the difference! With this flag, GNU C++ initializes `y' directlyfrom the call to foo ()without going through a temporary.

Normally GNU C++ allows conversion of enumtoint, but not the other way around. Use this option if you want GNU C++to allow conversion ofintto enumas well.
Produce smaller code for template declarations, by generating only asingle copy of each template function where it is defined.To use this option successfully, you must also mark all files thatuse templates with either `#pragma implementation' (the definition) or`#pragma interface' (declarations).

When your code is compiled with `-fexternal-templates', alltemplate instantiations are external. You must arrange for allnecessary instantiations to appear in the implementation file; you cando this with a typedef that references each instantiation needed.Conversely, when you compile using the default option`-fno-external-templates', all template instantiations areexplicitly internal.

Do not output global initializations (such as C++ constructors anddestructors) in the form used by the GNU linker (on systems where the GNUlinker is the standard method of handling them). Use this option whenyou want to use a non-GNU linker, which also requires using thecollect2program to make sure the system linker includesconstructors and destructors. (collect2is included in the GNU CC distribution.) For systems whichmustusecollect2, the compiler drivergccis configured to do this automatically.
These flags are used to get the compiler to compile programs fasterusing heuristics. They are not on by default since they are only effectiveabout half the time. The other half of the time programs compile moreslowly (and take more memory).

The first time the compiler must build a call to a member function (orreference to a data member), it must (1) determine whether the classimplements member functions of that name; (2) resolve which memberfunction to call (which involves figuring out what sorts of typeconversions need to be made); and (3) check the visibility of the memberfunction to the caller. All of this adds up to slower compilation.Normally, the second time a call is made to that member function (orreference to that data member), it must go through the same lengthyprocess again. This means that code like this

  cout << "This " << p << " has " << n << " legs.\n";

makes six passes through all three steps. By using a software cache,a ``hit'' significantly reduces this cost. Unfortunately, using thecache introduces another layer of mechanisms which must be implemented,and so incurs its own overhead. `-fmemoize-lookups' enablesthe software cache.

Because access privileges (visibility) to members and member functionsmay differ from one function context to the next, g++may need to flush the cache. With the `-fmemoize-lookups' flag, the cache is flushed after everyfunction that is compiled. The `-fsave-memoized' flag enables the same software cache, but when the compilerdetermines that the context of the last function compiled would yieldthe same access privileges of the next function to compile, itpreserves the cache. This is most helpful when defining many member functions for the sameclass: with the exception of member functions which are friends ofother classes, each member function has exactly the same accessprivileges as every other, and the cache need not be flushed.

Do not make member functions inline by default merely because they aredefined inside the class scope. Otherwise, when you specify-O, member functions defined inside class scope are compiledinline by default; i.e., you don't need to add `inline' in front ofthe member function name.
Consider the declaration int foo ();. In C++, this means that thefunction foo takes no arguments. In ANSI C, this is declaredint foo(void);. With the flag `-fno-strict-prototype',declaring functions with no arguments is equivalent to declaring itsargument list to be untyped, i.e., int foo (); is equivalent tosaying int foo (...);.
Normally, GNU C++ makes conservative assumptions about objects reachedthrough references. For example, the compiler must check that `a' is not null in code like the following:
    obj &a = g ();
    a.f (2);
Checking that references of this sort have non-null values requiresextra code, however, and it is unnecessary for many programs. You canuse `-fnonnull-objects' to omit the checks for null, if your program doesn't require thedefault checking.
These options control the recognition of the signature and sigof constructs for specifying abstract types. By default, theseconstructs are not recognized.
The incorporation of user-defined free store management into C++ hasmade assignment to this an anachronism. Therefore, by default GNUC++ treats the type of this in a member function of class Xto be X *const. In other words, it is illegal to assign tothis within a class member function. However, for backwardscompatibility, you can invoke the old behavior by using`-fthis-is-variable'.
Produce debugging information in the operating system's native format(for DBX or SDB or DWARF). GDB also can work with this debugginginformation. On most systems that use DBX format, `-g' enables useof extra debugging information that only GDB can use.

Unlike most other C compilers, GNU CC allows you to use `-g' with`-O'. The shortcuts taken by optimized code may occasionallyproduce surprising results: some variables you declared may not existat all; flow of control may briefly move where you did not expect it;some statements may not be executed because they compute constantresults or their values were already at hand; some statements mayexecute in different places because they were moved out of loops.

Nevertheless it proves possible to debug optimized output. This makesit reasonable to use the optimizer for programs that might have bugs.

Append directory dir to the list of directories searched for include files.
Add directory dir to the list of directories to be searchedfor `-l'.
Use the library named library when linking. (C++ programs often require `-lg++' for successful linking.)
Do not search the standard system directories for header files. Onlythe directories you have specified with-Ioptions (and the current directory, if appropriate) are searched.
Do not search for header files in the standard directories specific toC++, but do still search the other standard directories. (This optionis used when building libg++.)
Optimize. Optimizing compilation takes somewhat more time, and a lotmore memory for a large function.
-o file
Place output in file file.
Stop after the stage of compilation proper; do not assemble. The outputis an assembler code file for each non-assembler inputfile specified.
Attempt to support some aspects of traditional C compilers.

Specifically, for both C and C++ programs:

In the preprocessor, comments convert to nothing at all, rather thanto a space. This allows traditional token concatenation.
In the preprocessor, macro arguments are recognized within stringconstants in a macro definition (and their values are stringified,though without additional quote marks, when they appear in such acontext). The preprocessor always considers a string constant to endat a newline.
The preprocessor does not predefine the macro __STDC__ when you use`-traditional', but still predefines__GNUC__ (since the GNU extensions indicated by __GNUC__ are not affected by`-traditional'). If you need to write header files that workdifferently depending on whether `-traditional' is in use, bytesting both of these predefined macros you can distinguish foursituations: GNU C, traditional GNU C, other ANSI C compilers, andother old C compilers.

String ``constants'' are not necessarily constant; they are stored inwritable space, and identical looking constants are allocatedseparately.

For C++ programs only (not C), `-traditional' has one additional effect: assignment to thisis permitted. This is the same as the effect of `-fthis-is-variable'.

Undefine macro macro.
Issue warnings for conditions which pertain to usage that we recommendavoiding and that we believe is easy to avoid, even in conjunctionwith macros.
Warn when converting between different enumeration types.
In a derived class, the definitions of virtual functions must matchthe type signature of a virtual function declared in the base class.Use this option to request warnings when a derived class declares afunction that may be an erroneous attempt to define a virtualfunction: that is, warn when a function with the same name as avirtual function in the base class, but with a type signature thatdoesn't match any virtual functions from the base class.
When using templates in a C++ program, warn if debugging is not yetfully available.
Inhibit all warning messages.
Control how virtual function definitions are used, in a fashioncompatible withcfront1.x.



Two `#pragma' directives are supported for GNU C++, to permit using the sameheader file for two purposes: as a definition of interfaces to a givenobject class, and as the full definition of the contents of that object class.
#pragma interface
Use this directive in header files that define object classes, to savespace in most of the object files that use those classes. Normally,local copies of certain information (backup copies of inline memberfunctions, debugging information, and the internal tables thatimplement virtual functions) must be kept in each object file thatincludes class definitions. You can use this pragma to avoid suchduplication. When a header file containing `#pragma interface' is included in a compilation, this auxiliary informationwill not be generated (unless the main input source file itself uses`#pragma implementation'). Instead, the object files will contain references to beresolved at link time.
#pragma implementation
#pragma implementation !objects.h!
Use this pragma in a main input file, when you want full output fromincluded header files to be generated (and made globally visible).The included header file, in turn, should use `#pragma interface'. Backup copies of inline member functions, debugging information, andthe internal tables used to implement virtual functions are allgenerated in implementation files.

If you use `#pragma implementation' with no argument, it applies to an include file with the samebasename as your source file; for example, in `', `#pragma implementation' by itself is equivalent to `#pragma implementation "allclass.h"'. Use the string argument if you want a single implementationfile to include code from multiple header files.

There is no way to split up the contents of a single header file intomultiple implementation files.



file.h             C header (preprocessor) file

file.i            preprocessed C source file

file.C            C++ source file           C++ source file

file.cxx          C++ source file

file.s            assembly language file

file.o            object file

a.out             link edited output

TMPDIR/cc*        temporary files

LIBDIR/cpp        preprocessor

LIBDIR/cc1plus    compiler

LIBDIR/collect    linker front end needed on some machines

LIBDIR/libgcc.a   GCC subroutine library

/lib/crt[01n].o   start-up routine

LIBDIR/ccrt0      additional start-up routine for C++

/lib/libc.a       standard C library, see
/usr/include      standard directory for
LIBDIR/include    standard gcc directory for
LIBDIR/g++-includeadditional g++ directory for

LIBDIRis usually/usr/local/lib/machine/version.
TMPDIRcomes from the environment variable TMPDIR(default/usr/tmpif available, else/tmp). 


gcc(1), cpp(1), as(1), ld(1), gdb(1), adb(1), dbx(1), sdb(1).
`gcc', `cpp',`as',`ld',and `gdb'entries ininfo.
Using and Porting GNU CC (for version 2.0), Richard M. Stallman; The C Preprocessor, Richard M. Stallman;Debugging with GDB: the GNU Source-Level Debugger, Richard M. Stallman and Roland H. Pesch;Using as: the GNU Assembler, Dean Elsner, Jay Fenlason & friends;gld: the GNU linker, Steve Chamberlain and Roland Pesch.



For instructions on how to report bugs, see the GCC manual.



Copyright (c) 1991, 1992, 1993 Free Software Foundation, Inc.

Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.

Permission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided that theentire resulting derived work is distributed under the terms of apermission notice identical to this one.

Permission is granted to copy and distribute translations of thismanual into another language, under the above conditions for modifiedversions, except that this permission notice may be included intranslations approved by the Free Software Foundation instead of inthe original English. 


See the GNU CC Manual for the contributors to GNU CC.




This document was created byman2html,using the manual pages.