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.

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, in the directory `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 on rtfm.mit.edu under `pub/usenet/comp.lang.c++'.

The latest poop -- gcc-2.7.0

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

The big news is that version 2.7.0 has just been released. This, of course, means new FAQs. I haven't had a lot of time to whip out this section yet, so suggestions for improvement are welcome.

gcc-2.7.0 breaks declarations in "for" statements!

gcc-2.7.0 implements the new ANSI/ISO rule on the scope of variables declared in for loops.

for (int i = 1; i <= 10; i++) {
        // do something here
}
foo(i);

In the above example, most existing C++ compilers would pass the value 11 to the function foo. In gcc 2.7 and in the ANSI/ISO working paper, the scope of i is only the for loop body, so this is an error. So that old code can be compiled, the new gcc has a flag -fno-for-scope that causes the old rule to be used.

What's new in version 2.7.0 of gcc/g++

The long-awaited version 2.7.0 of gcc/g++ (along with a matching version of libg++) have now been released. This represents 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. For PostScript and PDF (Adobe Acrobat) versions, see the archive at ftp://research.att.com/dist/stdc++/WP. For HTML and ASCII versions, see ftp://ftp.cygnus.com/pub/g++. On the World Wide Web, see http://www.cygnus.com/~mrs/wp-draft.

How do I use the new repository code?

Because there is some disagreement about the details of the template repository mechanism, you'll need to obtain a patch from Cygnus Support to enable the 2.7.0 repository code. You can obtain the patch by anonymous FTP: `ftp://ftp.cygnus.com/pub/g++/gcc-2.7.0-repo.gz'.

After you've applied the patch, the -frepo flag will enable the repository mechanism. The flag works much like the existing -fno-implicit-templates flag, except that auxiliary files, with an `.rpo' extension, are built that specify what template expansions are needed. At link time, the (patched) collect program detects missing templates and recompiles some of the object files so that the required templates are expanded.

Note that the mechanism differs from that of cfront in that template definitions still must be visible at the point where they are to be expanded. No assumption is made that `foo.C' contains template definitions corresponding to template declarations in `foo.h'.

Jason Merrill writes: "To perform closure on a set of objects, just try to link them together. It will fail, but as a side effect all needed instances will be generated in the objects."

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 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.