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

Known Causes of Trouble with GNU CC

This section describes known problems that affect users of GNU CC. Most of these are not GNU CC bugs per se--if they were, we would fix them. But the result for a user may be like the result of a bug.

Some of these problems are due to bugs in other software, some are missing features that are too much work to add, and some are places where people's opinions differ as to what is best.

Actual Bugs We Haven't Fixed Yet

Installation Problems

This is a list of problems (and some apparent problems which don't really mean anything is wrong) that show up during installation of GNU CC.

Cross-Compiler Problems

You may run into problems with cross compilation on certain machines, for several reasons.

Interoperation

This section lists various difficulties encountered in using GNU C or GNU C++ together with other compilers or with the assemblers, linkers, libraries and debuggers on certain systems.

Problems Compiling Certain Programs

Certain programs have problems compiling.

Incompatibilities of GNU CC

There are several noteworthy incompatibilities between GNU C and most existing (non-ANSI) versions of C. The `-traditional' option eliminates many of these incompatibilities, but not all, by telling GNU C to behave like the other C compilers.

Fixed Header Files

GNU CC needs to install corrected versions of some system header files. This is because most target systems have some header files that won't work with GNU CC unless they are changed. Some have bugs, some are incompatible with ANSI C, and some depend on special features of other compilers.

Installing GNU CC automatically creates and installs the fixed header files, by running a program called fixincludes (or for certain targets an alternative such as fixinc.svr4). Normally, you don't need to pay attention to this. But there are cases where it doesn't do the right thing automatically.

Standard Libraries

GNU CC by itself attempts to be what the ISO/ANSI C standard calls a conforming freestanding implementation. This means all ANSI C language features are available, as well as the contents of `float.h', `limits.h', `stdarg.h', and `stddef.h'. The rest of the C library is supplied by the vendor of the operating system. If that C library doesn't conform to the C standards, then your programs might get warnings (especially when using `-Wall') that you don't expect.

For example, the sprintf function on SunOS 4.1.3 returns char * while the C standard says that sprintf returns an int. The fixincludes program could make the prototype for this function match the Standard, but that would be wrong, since the function will still return char *.

If you need a Standard compliant library, then you need to find one, as GNU CC does not provide one. The GNU C library (called glibc) has been ported to a number of operating systems, and provides ANSI/ISO, POSIX, BSD and SystemV compatibility. You could also ask your operating system vendor if newer libraries are available.

Disappointments and Misunderstandings

These problems are perhaps regrettable, but we don't know any practical way around them.

Common Misunderstandings with GNU C++

C++ is a complex language and an evolving one, and its standard definition (the ANSI C++ draft standard) is also evolving. As a result, your C++ compiler may occasionally surprise you, even when its behavior is correct. This section discusses some areas that frequently give rise to questions of this sort.

Declare and Define Static Members

When a class has static data members, it is not enough to declare the static member; you must also define it. For example:

class Foo
{
  ...
  void method();
  static int bar;
};

This declaration only establishes that the class Foo has an int named Foo::bar, and a member function named Foo::method. But you still need to define both method and bar elsewhere. According to the draft ANSI standard, you must supply an initializer in one (and only one) source file, such as:

int Foo::bar = 0;

Other C++ compilers may not correctly implement the standard behavior. As a result, when you switch to g++ from one of these compilers, you may discover that a program that appeared to work correctly in fact does not conform to the standard: g++ reports as undefined symbols any static data members that lack definitions.

Temporaries May Vanish Before You Expect

It is dangerous to use pointers or references to portions of a temporary object. The compiler may very well delete the object before you expect it to, leaving a pointer to garbage. The most common place where this problem crops up is in classes like the libg++ String class, that define a conversion function to type char * or const char *. However, any class that returns a pointer to some internal structure is potentially subject to this problem.

For example, a program may use a function strfunc that returns String objects, and another function charfunc that operates on pointers to char:

String strfunc ();
void charfunc (const char *);

In this situation, it may seem natural to write `charfunc (strfunc ());' based on the knowledge that class String has an explicit conversion to char pointers. However, what really happens is akin to `charfunc (strfunc ().convert ());', where the convert method is a function to do the same data conversion normally performed by a cast. Since the last use of the temporary String object is the call to the conversion function, the compiler may delete that object before actually calling charfunc. The compiler has no way of knowing that deleting the String object will invalidate the pointer. The pointer then points to garbage, so that by the time charfunc is called, it gets an invalid argument.

Code like this may run successfully under some other compilers, especially those that delete temporaries relatively late. However, the GNU C++ behavior is also standard-conforming, so if your program depends on late destruction of temporaries it is not portable.

If you think this is surprising, you should be aware that the ANSI C++ committee continues to debate the lifetime-of-temporaries problem.

For now, at least, the safe way to write such code is to give the temporary a name, which forces it to remain until the end of the scope of the name. For example:

String& tmp = strfunc ();
charfunc (tmp);

Caveats of using protoize

The conversion programs protoize and unprotoize can sometimes change a source file in a way that won't work unless you rearrange it.

Certain Changes We Don't Want to Make

This section lists changes that people frequently request, but which we do not make because we think GNU CC is better without them.

Warning Messages and Error Messages

The GNU compiler can produce two kinds of diagnostics: errors and warnings. Each kind has a different purpose:

Warnings may indicate danger points where you should check to make sure that your program really does what you intend; or the use of obsolete features; or the use of nonstandard features of GNU C or C++. Many warnings are issued only if you ask for them, with one of the `-W' options (for instance, `-Wall' requests a variety of useful warnings).

GNU CC always tries to compile your program if possible; it never gratuitously rejects a program whose meaning is clear merely because (for instance) it fails to conform to a standard. In some cases, however, the C and C++ standards specify that certain extensions are forbidden, and a diagnostic must be issued by a conforming compiler. The `-pedantic' option tells GNU CC to issue warnings in such cases; `-pedantic-errors' says to make them errors instead. This does not mean that all non-ANSI constructs get warnings or errors.

See section Options to Request or Suppress Warnings, for more detail on these and related command-line options.


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