Go to the first, previous, next, last section, table of contents.

This is a list of frequently asked questions (FAQ) for g++ users; thanks to all those who sent suggestions for improvements. Thanks to Marcus Speh for doing the index. A hypertext version is available on the World Wide Web at ``http://www.cygnus.com/misc/g++FAQ_toc.html'`.

Please send updates and corrections to the FAQ to `jbuck@synopsys.com`. Please do not use me as a resource to get your questions answered; that's what ``gnu.g++.help'` is for and I don't have the time to support the net's use of g++.

Many FAQs, including this one, are available on the archive site "rtfm.mit.edu"; see
``ftp://rtfm.mit.edu/pub/usenet/news.answers'`. This FAQ may be found in the subdirectory g++-FAQ.

This FAQ is intended to supplement, not replace, Marshall Cline's excellent FAQ for the C++ language and for the newsgroup ``comp.lang.c++'`. Especially if g++ is the first C++ compiler you've ever used, the question "How do I do <X> with g++?" is probably really "How do I do <X> in C++?". You can find this FAQ at ``ftp://rtfm.mit.edu/pub/usenet/comp.lang.c++'`, or in HTML form at ``http://www.cerfnet.com/~mpcline/On-Line-C++-FAQs/'`.

# The latest poop -- gcc-2.7.x

This section is intended to describe more recent changes to g++, libg++, and such. Some things in this section will eventually move elsewhere.

News: as I write this (late February 1996) the gateway connecting the bug-g++ mailing list and the ``gnu.g++.bug'` newsgroup is broken. Please mail, do not post bug reports.

## What's new in version 2.7.x of gcc/g++

The current version of gcc/g++ is 2.7.2.1, released August 14, 1996. The current version of libg++ is 2.7.2, released July 4, 1996.

Note that gcc 2.7.2.1 just consists of several small patches to gcc-2.7.2. The release is mainly intended to fix platform-specific bugs and does not affect the C++ "front end" of the compiler (the part that parses your C++ code).

The 2.7.x releases represent a great deal of work on the part of the g++ maintainers to fix outstanding bugs and move the compiler closer to the current ANSI/ISO standards committee's working paper, including supporting many of the new features that have been added to the language. I recommend that everyone read the NEWS file contained in the distribution (and that system administrators make the file available to their users). I've borrowed liberally from this file here.

If any features seem unfamiliar, you will probably want to look at the recently-released public review copy of the C++ Working Paper:

- PostScript and PDF (Adobe Acrobat): see ``ftp://research.att.com/dist/c++std/WP'`.
- HTML and ASCII versions: see ``ftp://ftp.cygnus.com/pub/g++'`.
- World Wide Web: see ``http://www.cygnus.com/misc/wp/'`.

Here are the main points:

- As described above, the scope of variables declared in the initialization part of a for statement has been changed; such variables are now visible only in the loop body. Use `-fno-for-scope` to get the old behavior. You'll need this flag to build groff version 1.09, Ptolemy, and many other free software packages.
- Code that does not use #pragma interface/implementation will most likely shrink dramatically, as g++ now only emits the vtable for a class in the translation unit where its first non-inline, non-abstract virtual function is defined.
- Support for automatic template instantiation has not been enabled in the official distribution, due to a disagreement over design philosophies. But you can get a patch from Cygnus to turn it on; retrieve the patch from ``ftp://ftp.cygnus.com/pub/g++/gcc-2.7.2-repo.gz'` to patch gcc-2.7.2 (there are also patches for earlier gcc versions).
- See section Problems and limitations with exceptions
- Support for Run-Time Type Identification has been added with `-frtti`. This support is still in alpha; one major restriction is that any file compiled with `-frtti` must include `<typeinfo>` (not `typeinfo.h` as the NEWS file says). Also, all C++ code you link with (including libg++) has to be built with `-frtti`, so it's still tricky to use.
- Synthesis of compiler-generated constructors, destructors and assignment operators is now deferred until the functions are used.
- The parsing of expressions such as `a ? b : c = 1` has changed from `(a ? b : c) = 1` to `a ? b : (c = 1)`. This is a new C/C++ incompatibility brought to you by the ANSI/ISO standards committee.
- The operator keywords and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor and xor_eq are now supported. Use `-ansi` or `-foperator-names` to enable them.
- The `explicit` keyword is now supported. `explicit` is used to mark constructors and type conversion operators that should not be used implicitly.
- Handling of user-defined type conversion has been improved.
- Explicit instantiation of template methods is now supported. Also, `inline template class foo<int>;` can be used to emit only the vtable for a template class.
- With -fcheck-new, g++ will check the return value of all calls to operator new, and not attempt to modify a returned null pointer.
- collect2 now demangles linker output, and c++filt has become part of the gcc distribution.
- Improvements to template instantiation: only members actually used are instantiated. (Actually this is not quite true: some inline templates that are not successfully inlined may be expanded even though they are not needed).

## The GNU Standard C++ Library

The GNU Standard C++ Library (also called the "GNU ANSI C++ Library" in places in the code) is not libg++, though it is included in the libg++ distribution. Rather, it contains classes and functions required by the ANSI/ISO standard. The copyright conditions are the same as those for for the iostreams classes; the LGPL is not used (See section What are the rules for shipping code built with g++ and libg++?).

This library, libstdc++, is in the libg++ distribution in versions 2.6.2 and later. It requires at least gcc 2.6.3 to build the libg++-2.6.2 version; use at least gcc 2.7.0 to build the libg++ 2.7.0 version. It contains a hacked-up version of HP's implementation of the Standard Template Library (see See section Does g++ support the Standard Template Library?). I've successfully used this Standard Template Library version to build a number of the demos you'll see on various web pages.

As of version 2.7.0, the streams classes are now in libstdc++ instead of libg++, and libiostream is being phased out (don't use it). The g++ program searches this library.

Go to the first, previous, next, last section, table of contents.