xref: /openbsd-src/gnu/usr.bin/gcc/gcc/doc/trouble.texi (revision 4e43c760ad4cd5f644ec700462679d05749498d8)
1c87b03e5Sespie@c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
2c87b03e5Sespie@c 1999, 2000, 2001 Free Software Foundation, Inc.
3c87b03e5Sespie@c This is part of the GCC manual.
4c87b03e5Sespie@c For copying conditions, see the file gcc.texi.
5c87b03e5Sespie
6c87b03e5Sespie@node Trouble
7c87b03e5Sespie@chapter Known Causes of Trouble with GCC
8c87b03e5Sespie@cindex bugs, known
9c87b03e5Sespie@cindex installation trouble
10c87b03e5Sespie@cindex known causes of trouble
11c87b03e5Sespie
12c87b03e5SespieThis section describes known problems that affect users of GCC@.  Most
13c87b03e5Sespieof these are not GCC bugs per se---if they were, we would fix them.
14c87b03e5SespieBut the result for a user may be like the result of a bug.
15c87b03e5Sespie
16c87b03e5SespieSome of these problems are due to bugs in other software, some are
17c87b03e5Sespiemissing features that are too much work to add, and some are places
18c87b03e5Sespiewhere people's opinions differ as to what is best.
19c87b03e5Sespie
20c87b03e5Sespie@menu
21c87b03e5Sespie* Actual Bugs::		      Bugs we will fix later.
22c87b03e5Sespie* Cross-Compiler Problems::   Common problems of cross compiling with GCC.
23c87b03e5Sespie* Interoperation::      Problems using GCC with other compilers,
24c87b03e5Sespie			   and with certain linkers, assemblers and debuggers.
25c87b03e5Sespie* External Bugs::	Problems compiling certain programs.
26c87b03e5Sespie* Incompatibilities::   GCC is incompatible with traditional C.
27c87b03e5Sespie* Fixed Headers::       GCC uses corrected versions of system header files.
28c87b03e5Sespie                           This is necessary, but doesn't always work smoothly.
29c87b03e5Sespie* Standard Libraries::  GCC uses the system C library, which might not be
30c87b03e5Sespie                           compliant with the ISO C standard.
31c87b03e5Sespie* Disappointments::     Regrettable things we can't change, but not quite bugs.
32c87b03e5Sespie* C++ Misunderstandings::     Common misunderstandings with GNU C++.
33c87b03e5Sespie* Protoize Caveats::    Things to watch out for when using @code{protoize}.
34c87b03e5Sespie* Non-bugs::		Things we think are right, but some others disagree.
35c87b03e5Sespie* Warnings and Errors:: Which problems in your code get warnings,
36c87b03e5Sespie                         and which get errors.
37c87b03e5Sespie@end menu
38c87b03e5Sespie
39c87b03e5Sespie@node Actual Bugs
40c87b03e5Sespie@section Actual Bugs We Haven't Fixed Yet
41c87b03e5Sespie
42c87b03e5Sespie@itemize @bullet
43c87b03e5Sespie@item
44c87b03e5SespieThe @code{fixincludes} script interacts badly with automounters; if the
45c87b03e5Sespiedirectory of system header files is automounted, it tends to be
46c87b03e5Sespieunmounted while @code{fixincludes} is running.  This would seem to be a
47c87b03e5Sespiebug in the automounter.  We don't know any good way to work around it.
48c87b03e5Sespie
49c87b03e5Sespie@item
50c87b03e5SespieThe @code{fixproto} script will sometimes add prototypes for the
51c87b03e5Sespie@code{sigsetjmp} and @code{siglongjmp} functions that reference the
52c87b03e5Sespie@code{jmp_buf} type before that type is defined.  To work around this,
53c87b03e5Sespieedit the offending file and place the typedef in front of the
54c87b03e5Sespieprototypes.
55c87b03e5Sespie
56c87b03e5Sespie@item
57c87b03e5Sespie@opindex pedantic-errors
58c87b03e5SespieWhen @option{-pedantic-errors} is specified, GCC will incorrectly give
59c87b03e5Sespiean error message when a function name is specified in an expression
60c87b03e5Sespieinvolving the comma operator.
61c87b03e5Sespie@end itemize
62c87b03e5Sespie
63c87b03e5Sespie@node Cross-Compiler Problems
64c87b03e5Sespie@section Cross-Compiler Problems
65c87b03e5Sespie
66c87b03e5SespieYou may run into problems with cross compilation on certain machines,
67c87b03e5Sespiefor several reasons.
68c87b03e5Sespie
69c87b03e5Sespie@itemize @bullet
70c87b03e5Sespie@item
71c87b03e5SespieCross compilation can run into trouble for certain machines because
72c87b03e5Sespiesome target machines' assemblers require floating point numbers to be
73c87b03e5Sespiewritten as @emph{integer} constants in certain contexts.
74c87b03e5Sespie
75c87b03e5SespieThe compiler writes these integer constants by examining the floating
76c87b03e5Sespiepoint value as an integer and printing that integer, because this is
77c87b03e5Sespiesimple to write and independent of the details of the floating point
78c87b03e5Sespierepresentation.  But this does not work if the compiler is running on
79c87b03e5Sespiea different machine with an incompatible floating point format, or
80c87b03e5Sespieeven a different byte-ordering.
81c87b03e5Sespie
82c87b03e5SespieIn addition, correct constant folding of floating point values
83c87b03e5Sespierequires representing them in the target machine's format.
84c87b03e5Sespie(The C standard does not quite require this, but in practice
85c87b03e5Sespieit is the only way to win.)
86c87b03e5Sespie
87c87b03e5SespieIt is now possible to overcome these problems by defining macros such
88c87b03e5Sespieas @code{REAL_VALUE_TYPE}.  But doing so is a substantial amount of
89c87b03e5Sespiework for each target machine.
90c87b03e5Sespie@xref{Cross-compilation,,Cross Compilation and Floating Point,
91c87b03e5Sespiegccint, GNU Compiler Collection (GCC) Internals}.
92c87b03e5Sespie
93c87b03e5Sespie@item
94c87b03e5SespieAt present, the program @file{mips-tfile} which adds debug
95c87b03e5Sespiesupport to object files on MIPS systems does not work in a cross
96c87b03e5Sespiecompile environment.
97c87b03e5Sespie@end itemize
98c87b03e5Sespie
99c87b03e5Sespie@node Interoperation
100c87b03e5Sespie@section Interoperation
101c87b03e5Sespie
102c87b03e5SespieThis section lists various difficulties encountered in using GCC
103c87b03e5Sespietogether with other compilers or with the assemblers, linkers,
104c87b03e5Sespielibraries and debuggers on certain systems.
105c87b03e5Sespie
106c87b03e5Sespie@itemize @bullet
107c87b03e5Sespie@item
108c87b03e5SespieOn many platforms, GCC supports a different ABI for C++ than do other
109c87b03e5Sespiecompilers, so the object files compiled by GCC cannot be used with object
110c87b03e5Sespiefiles generated by another C++ compiler.
111c87b03e5Sespie
112c87b03e5SespieAn area where the difference is most apparent is name mangling.  The use
113c87b03e5Sespieof different name mangling is intentional, to protect you from more subtle
114c87b03e5Sespieproblems.
115c87b03e5SespieCompilers differ as to many internal details of C++ implementation,
116c87b03e5Sespieincluding: how class instances are laid out, how multiple inheritance is
117c87b03e5Sespieimplemented, and how virtual function calls are handled.  If the name
118c87b03e5Sespieencoding were made the same, your programs would link against libraries
119c87b03e5Sespieprovided from other compilers---but the programs would then crash when
120c87b03e5Sespierun.  Incompatible libraries are then detected at link time, rather than
121c87b03e5Sespieat run time.
122c87b03e5Sespie
123c87b03e5Sespie@item
124c87b03e5SespieOlder GDB versions sometimes fail to read the output of GCC version
125c87b03e5Sespie2.  If you have trouble, get GDB version 4.4 or later.
126c87b03e5Sespie
127c87b03e5Sespie@item
128c87b03e5Sespie@cindex DBX
129c87b03e5SespieDBX rejects some files produced by GCC, though it accepts similar
130c87b03e5Sespieconstructs in output from PCC@.  Until someone can supply a coherent
131c87b03e5Sespiedescription of what is valid DBX input and what is not, there is
132c87b03e5Sespienothing I can do about these problems.  You are on your own.
133c87b03e5Sespie
134c87b03e5Sespie@item
135c87b03e5SespieThe GNU assembler (GAS) does not support PIC@.  To generate PIC code, you
136c87b03e5Sespiemust use some other assembler, such as @file{/bin/as}.
137c87b03e5Sespie
138c87b03e5Sespie@item
139c87b03e5SespieOn some BSD systems, including some versions of Ultrix, use of profiling
140c87b03e5Sespiecauses static variable destructors (currently used only in C++) not to
141c87b03e5Sespiebe run.
142c87b03e5Sespie
143c87b03e5Sespie@ignore
144c87b03e5Sespie@cindex @code{vfork}, for the Sun-4
145c87b03e5Sespie@item
146c87b03e5SespieThere is a bug in @code{vfork} on the Sun-4 which causes the registers
147c87b03e5Sespieof the child process to clobber those of the parent.  Because of this,
148c87b03e5Sespieprograms that call @code{vfork} are likely to lose when compiled
149c87b03e5Sespieoptimized with GCC when the child code alters registers which contain
150c87b03e5SespieC variables in the parent.  This affects variables which are live in the
151c87b03e5Sespieparent across the call to @code{vfork}.
152c87b03e5Sespie
153c87b03e5SespieIf you encounter this, you can work around the problem by declaring
154c87b03e5Sespievariables @code{volatile} in the function that calls @code{vfork}, until
155c87b03e5Sespiethe problem goes away, or by not declaring them @code{register} and not
156c87b03e5Sespieusing @option{-O} for those source files.
157c87b03e5Sespie@end ignore
158c87b03e5Sespie
159c87b03e5Sespie@item
160c87b03e5SespieOn some SGI systems, when you use @option{-lgl_s} as an option,
161c87b03e5Sespieit gets translated magically to @samp{-lgl_s -lX11_s -lc_s}.
162c87b03e5SespieNaturally, this does not happen when you use GCC@.
163c87b03e5SespieYou must specify all three options explicitly.
164c87b03e5Sespie
165c87b03e5Sespie@item
166c87b03e5SespieOn a SPARC, GCC aligns all values of type @code{double} on an 8-byte
167c87b03e5Sespieboundary, and it expects every @code{double} to be so aligned.  The Sun
168c87b03e5Sespiecompiler usually gives @code{double} values 8-byte alignment, with one
169c87b03e5Sespieexception: function arguments of type @code{double} may not be aligned.
170c87b03e5Sespie
171c87b03e5SespieAs a result, if a function compiled with Sun CC takes the address of an
172c87b03e5Sespieargument of type @code{double} and passes this pointer of type
173c87b03e5Sespie@code{double *} to a function compiled with GCC, dereferencing the
174c87b03e5Sespiepointer may cause a fatal signal.
175c87b03e5Sespie
176c87b03e5SespieOne way to solve this problem is to compile your entire program with GCC@.
177c87b03e5SespieAnother solution is to modify the function that is compiled with
178c87b03e5SespieSun CC to copy the argument into a local variable; local variables
179c87b03e5Sespieare always properly aligned.  A third solution is to modify the function
180c87b03e5Sespiethat uses the pointer to dereference it via the following function
181c87b03e5Sespie@code{access_double} instead of directly with @samp{*}:
182c87b03e5Sespie
183c87b03e5Sespie@smallexample
184c87b03e5Sespieinline double
185c87b03e5Sespieaccess_double (double *unaligned_ptr)
186c87b03e5Sespie@{
187c87b03e5Sespie  union d2i @{ double d; int i[2]; @};
188c87b03e5Sespie
189c87b03e5Sespie  union d2i *p = (union d2i *) unaligned_ptr;
190c87b03e5Sespie  union d2i u;
191c87b03e5Sespie
192c87b03e5Sespie  u.i[0] = p->i[0];
193c87b03e5Sespie  u.i[1] = p->i[1];
194c87b03e5Sespie
195c87b03e5Sespie  return u.d;
196c87b03e5Sespie@}
197c87b03e5Sespie@end smallexample
198c87b03e5Sespie
199c87b03e5Sespie@noindent
200c87b03e5SespieStoring into the pointer can be done likewise with the same union.
201c87b03e5Sespie
202c87b03e5Sespie@item
203c87b03e5SespieOn Solaris, the @code{malloc} function in the @file{libmalloc.a} library
204c87b03e5Sespiemay allocate memory that is only 4 byte aligned.  Since GCC on the
205c87b03e5SespieSPARC assumes that doubles are 8 byte aligned, this may result in a
206c87b03e5Sespiefatal signal if doubles are stored in memory allocated by the
207c87b03e5Sespie@file{libmalloc.a} library.
208c87b03e5Sespie
209c87b03e5SespieThe solution is to not use the @file{libmalloc.a} library.  Use instead
210c87b03e5Sespie@code{malloc} and related functions from @file{libc.a}; they do not have
211c87b03e5Sespiethis problem.
212c87b03e5Sespie
213c87b03e5Sespie@item
214c87b03e5SespieSun forgot to include a static version of @file{libdl.a} with some
215c87b03e5Sespieversions of SunOS (mainly 4.1).  This results in undefined symbols when
216c87b03e5Sespielinking static binaries (that is, if you use @option{-static}).  If you
217c87b03e5Sespiesee undefined symbols @code{_dlclose}, @code{_dlsym} or @code{_dlopen}
218c87b03e5Sespiewhen linking, compile and link against the file
219c87b03e5Sespie@file{mit/util/misc/dlsym.c} from the MIT version of X windows.
220c87b03e5Sespie
221c87b03e5Sespie@item
222c87b03e5SespieThe 128-bit long double format that the SPARC port supports currently
223c87b03e5Sespieworks by using the architecturally defined quad-word floating point
224c87b03e5Sespieinstructions.  Since there is no hardware that supports these
225c87b03e5Sespieinstructions they must be emulated by the operating system.  Long
226c87b03e5Sespiedoubles do not work in Sun OS versions 4.0.3 and earlier, because the
227c87b03e5Sespiekernel emulator uses an obsolete and incompatible format.  Long doubles
228c87b03e5Sespiedo not work in Sun OS version 4.1.1 due to a problem in a Sun library.
229c87b03e5SespieLong doubles do work on Sun OS versions 4.1.2 and higher, but GCC
230c87b03e5Sespiedoes not enable them by default.  Long doubles appear to work in Sun OS
231c87b03e5Sespie5.x (Solaris 2.x).
232c87b03e5Sespie
233c87b03e5Sespie@item
234c87b03e5SespieOn HP-UX version 9.01 on the HP PA, the HP compiler @code{cc} does not
235c87b03e5Sespiecompile GCC correctly.  We do not yet know why.  However, GCC
236c87b03e5Sespiecompiled on earlier HP-UX versions works properly on HP-UX 9.01 and can
237c87b03e5Sespiecompile itself properly on 9.01.
238c87b03e5Sespie
239c87b03e5Sespie@item
240c87b03e5SespieOn the HP PA machine, ADB sometimes fails to work on functions compiled
241c87b03e5Sespiewith GCC@.  Specifically, it fails to work on functions that use
242c87b03e5Sespie@code{alloca} or variable-size arrays.  This is because GCC doesn't
243c87b03e5Sespiegenerate HP-UX unwind descriptors for such functions.  It may even be
244c87b03e5Sespieimpossible to generate them.
245c87b03e5Sespie
246c87b03e5Sespie@item
247c87b03e5SespieDebugging (@option{-g}) is not supported on the HP PA machine, unless you use
248c87b03e5Sespiethe preliminary GNU tools.
249c87b03e5Sespie
250c87b03e5Sespie@item
251c87b03e5SespieTaking the address of a label may generate errors from the HP-UX
252c87b03e5SespiePA assembler.  GAS for the PA does not have this problem.
253c87b03e5Sespie
254c87b03e5Sespie@item
255c87b03e5SespieUsing floating point parameters for indirect calls to static functions
256c87b03e5Sespiewill not work when using the HP assembler.  There simply is no way for GCC
257c87b03e5Sespieto specify what registers hold arguments for static functions when using
258c87b03e5Sespiethe HP assembler.  GAS for the PA does not have this problem.
259c87b03e5Sespie
260c87b03e5Sespie@item
261c87b03e5SespieIn extremely rare cases involving some very large functions you may
262c87b03e5Sespiereceive errors from the HP linker complaining about an out of bounds
263c87b03e5Sespieunconditional branch offset.  This used to occur more often in previous
264c87b03e5Sespieversions of GCC, but is now exceptionally rare.  If you should run
265c87b03e5Sespieinto it, you can work around by making your function smaller.
266c87b03e5Sespie
267c87b03e5Sespie@item
268c87b03e5SespieGCC compiled code sometimes emits warnings from the HP-UX assembler of
269c87b03e5Sespiethe form:
270c87b03e5Sespie
271c87b03e5Sespie@smallexample
272c87b03e5Sespie(warning) Use of GR3 when
273c87b03e5Sespie  frame >= 8192 may cause conflict.
274c87b03e5Sespie@end smallexample
275c87b03e5Sespie
276c87b03e5SespieThese warnings are harmless and can be safely ignored.
277c87b03e5Sespie
278c87b03e5Sespie@item
279c87b03e5SespieOn the IBM RS/6000, compiling code of the form
280c87b03e5Sespie
281c87b03e5Sespie@smallexample
282c87b03e5Sespieextern int foo;
283c87b03e5Sespie
284c87b03e5Sespie@dots{} foo @dots{}
285c87b03e5Sespie
286c87b03e5Sespiestatic int foo;
287c87b03e5Sespie@end smallexample
288c87b03e5Sespie
289c87b03e5Sespie@noindent
290c87b03e5Sespiewill cause the linker to report an undefined symbol @code{foo}.
291c87b03e5SespieAlthough this behavior differs from most other systems, it is not a
292c87b03e5Sespiebug because redefining an @code{extern} variable as @code{static}
293c87b03e5Sespieis undefined in ISO C@.
294c87b03e5Sespie
295c87b03e5Sespie@item
296c87b03e5SespieIn extremely rare cases involving some very large functions you may
297c87b03e5Sespiereceive errors from the AIX Assembler complaining about a displacement
298c87b03e5Sespiethat is too large.  If you should run into it, you can work around by
299c87b03e5Sespiemaking your function smaller.
300c87b03e5Sespie
301c87b03e5Sespie@item
302c87b03e5SespieThe @file{libstdc++.a} library in GCC relies on the SVR4 dynamic
303c87b03e5Sespielinker semantics which merges global symbols between libraries and
304c87b03e5Sespieapplications, especially necessary for C++ streams functionality.
305c87b03e5SespieThis is not the default behavior of AIX shared libraries and dynamic
306c87b03e5Sespielinking.  @file{libstdc++.a} is built on AIX with ``runtime-linking''
307c87b03e5Sespieenabled so that symbol merging can occur.  To utilize this feature,
308c87b03e5Sespiethe application linked with @file{libstdc++.a} must include the
309c87b03e5Sespie@option{-Wl,-brtl} flag on the link line.  G++ cannot impose this
310c87b03e5Sespiebecause this option may interfere with the semantics of the user
311c87b03e5Sespieprogram and users may not always use @samp{g++} to link his or her
312c87b03e5Sespieapplication. Applications are not required to use the
313c87b03e5Sespie@option{-Wl,-brtl} flag on the link line---the rest of the
314c87b03e5Sespie@file{libstdc++.a} library which is not dependent on the symbol
315c87b03e5Sespiemerging semantics will continue to function correctly.
316c87b03e5Sespie
317c87b03e5Sespie@item
318c87b03e5SespieAn application can interpose its own definition of functions for
319c87b03e5Sespiefunctions invoked by @file{libstdc++.a} with ``runtime-linking''
320c87b03e5Sespieenabled on AIX.  To accomplish this the application must be linked
321c87b03e5Sespiewith ``runtime-linking'' option and the functions explicitly must be
322c87b03e5Sespieexported by the application (@option{-Wl,-brtl,-bE:exportfile}).
323c87b03e5Sespie
324c87b03e5Sespie@item
325c87b03e5SespieAIX on the RS/6000 provides support (NLS) for environments outside of
326c87b03e5Sespiethe United States.  Compilers and assemblers use NLS to support
327c87b03e5Sespielocale-specific representations of various objects including
328c87b03e5Sespiefloating-point numbers (@samp{.} vs @samp{,} for separating decimal
329c87b03e5Sespiefractions). There have been problems reported where the library linked
330c87b03e5Sespiewith GCC does not produce the same floating-point formats that the
331c87b03e5Sespieassembler accepts. If you have this problem, set the @env{LANG}
332c87b03e5Sespieenvironment variable to @samp{C} or @samp{En_US}.
333c87b03e5Sespie
334c87b03e5Sespie@item
335c87b03e5Sespie@opindex fdollars-in-identifiers
336c87b03e5SespieEven if you specify @option{-fdollars-in-identifiers},
337c87b03e5Sespieyou cannot successfully use @samp{$} in identifiers on the RS/6000 due
338c87b03e5Sespieto a restriction in the IBM assembler.  GAS supports these
339c87b03e5Sespieidentifiers.
340c87b03e5Sespie
341c87b03e5Sespie@cindex VAX calling convention
342c87b03e5Sespie@cindex Ultrix calling convention
343c87b03e5Sespie@item
344c87b03e5Sespie@opindex fcall-saved
345c87b03e5SespieOn Ultrix, the Fortran compiler expects registers 2 through 5 to be saved
346c87b03e5Sespieby function calls.  However, the C compiler uses conventions compatible
347c87b03e5Sespiewith BSD Unix: registers 2 through 5 may be clobbered by function calls.
348c87b03e5Sespie
349c87b03e5SespieGCC uses the same convention as the Ultrix C compiler.  You can use
350c87b03e5Sespiethese options to produce code compatible with the Fortran compiler:
351c87b03e5Sespie
352c87b03e5Sespie@smallexample
353c87b03e5Sespie-fcall-saved-r2 -fcall-saved-r3 -fcall-saved-r4 -fcall-saved-r5
354c87b03e5Sespie@end smallexample
355c87b03e5Sespie
356c87b03e5Sespie@item
357c87b03e5SespieOn the Alpha, you may get assembler errors about invalid syntax as a
358c87b03e5Sespieresult of floating point constants.  This is due to a bug in the C
359c87b03e5Sespielibrary functions @code{ecvt}, @code{fcvt} and @code{gcvt}.  Given valid
360c87b03e5Sespiefloating point numbers, they sometimes print @samp{NaN}.
361c87b03e5Sespie@end itemize
362c87b03e5Sespie
363c87b03e5Sespie@node External Bugs
364c87b03e5Sespie@section Problems Compiling Certain Programs
365c87b03e5Sespie
366c87b03e5Sespie@c prevent bad page break with this line
367c87b03e5SespieCertain programs have problems compiling.
368c87b03e5Sespie
369c87b03e5Sespie@itemize @bullet
370c87b03e5Sespie@item
371c87b03e5SespieParse errors may occur compiling X11 on a Decstation running Ultrix 4.2
372c87b03e5Sespiebecause of problems in DEC's versions of the X11 header files
373c87b03e5Sespie@file{X11/Xlib.h} and @file{X11/Xutil.h}.  People recommend adding
374c87b03e5Sespie@option{-I/usr/include/mit} to use the MIT versions of the header files,
375c87b03e5Sespieor fixing the header files by adding this:
376c87b03e5Sespie
377c87b03e5Sespie@example
378c87b03e5Sespie#ifdef __STDC__
379c87b03e5Sespie#define NeedFunctionPrototypes 0
380c87b03e5Sespie#endif
381c87b03e5Sespie@end example
382c87b03e5Sespie
383c87b03e5Sespie@item
384c87b03e5SespieOn various 386 Unix systems derived from System V, including SCO, ISC,
385c87b03e5Sespieand ESIX, you may get error messages about running out of virtual memory
386c87b03e5Sespiewhile compiling certain programs.
387c87b03e5Sespie
388c87b03e5SespieYou can prevent this problem by linking GCC with the GNU malloc
389c87b03e5Sespie(which thus replaces the malloc that comes with the system).  GNU malloc
390c87b03e5Sespieis available as a separate package, and also in the file
391c87b03e5Sespie@file{src/gmalloc.c} in the GNU Emacs 19 distribution.
392c87b03e5Sespie
393c87b03e5SespieIf you have installed GNU malloc as a separate library package, use this
394c87b03e5Sespieoption when you relink GCC:
395c87b03e5Sespie
396c87b03e5Sespie@example
397c87b03e5SespieMALLOC=/usr/local/lib/libgmalloc.a
398c87b03e5Sespie@end example
399c87b03e5Sespie
400c87b03e5SespieAlternatively, if you have compiled @file{gmalloc.c} from Emacs 19, copy
401c87b03e5Sespiethe object file to @file{gmalloc.o} and use this option when you relink
402c87b03e5SespieGCC:
403c87b03e5Sespie
404c87b03e5Sespie@example
405c87b03e5SespieMALLOC=gmalloc.o
406c87b03e5Sespie@end example
407c87b03e5Sespie@end itemize
408c87b03e5Sespie
409c87b03e5Sespie@node Incompatibilities
410c87b03e5Sespie@section Incompatibilities of GCC
411c87b03e5Sespie@cindex incompatibilities of GCC
412c87b03e5Sespie@opindex traditional
413c87b03e5Sespie
414c87b03e5SespieThere are several noteworthy incompatibilities between GNU C and K&R
415c87b03e5Sespie(non-ISO) versions of C@.
416c87b03e5Sespie
417c87b03e5Sespie@itemize @bullet
418c87b03e5Sespie@cindex string constants
419c87b03e5Sespie@cindex read-only strings
420c87b03e5Sespie@cindex shared strings
421c87b03e5Sespie@item
422c87b03e5SespieGCC normally makes string constants read-only.  If several
423c87b03e5Sespieidentical-looking string constants are used, GCC stores only one
424c87b03e5Sespiecopy of the string.
425c87b03e5Sespie
426c87b03e5Sespie@cindex @code{mktemp}, and constant strings
427c87b03e5SespieOne consequence is that you cannot call @code{mktemp} with a string
428c87b03e5Sespieconstant argument.  The function @code{mktemp} always alters the
429c87b03e5Sespiestring its argument points to.
430c87b03e5Sespie
431c87b03e5Sespie@cindex @code{sscanf}, and constant strings
432c87b03e5Sespie@cindex @code{fscanf}, and constant strings
433c87b03e5Sespie@cindex @code{scanf}, and constant strings
434c87b03e5SespieAnother consequence is that @code{sscanf} does not work on some systems
435c87b03e5Sespiewhen passed a string constant as its format control string or input.
436c87b03e5SespieThis is because @code{sscanf} incorrectly tries to write into the string
437c87b03e5Sespieconstant.  Likewise @code{fscanf} and @code{scanf}.
438c87b03e5Sespie
439c87b03e5Sespie@opindex fwritable-strings
440c87b03e5SespieThe best solution to these problems is to change the program to use
441c87b03e5Sespie@code{char}-array variables with initialization strings for these
442c87b03e5Sespiepurposes instead of string constants.  But if this is not possible,
443c87b03e5Sespieyou can use the @option{-fwritable-strings} flag, which directs GCC
444c87b03e5Sespieto handle string constants the same way most C compilers do.
445c87b03e5Sespie
446c87b03e5Sespie@item
447c87b03e5Sespie@code{-2147483648} is positive.
448c87b03e5Sespie
449c87b03e5SespieThis is because 2147483648 cannot fit in the type @code{int}, so
450c87b03e5Sespie(following the ISO C rules) its data type is @code{unsigned long int}.
451c87b03e5SespieNegating this value yields 2147483648 again.
452c87b03e5Sespie
453c87b03e5Sespie@item
454c87b03e5SespieGCC does not substitute macro arguments when they appear inside of
455c87b03e5Sespiestring constants.  For example, the following macro in GCC
456c87b03e5Sespie
457c87b03e5Sespie@example
458c87b03e5Sespie#define foo(a) "a"
459c87b03e5Sespie@end example
460c87b03e5Sespie
461c87b03e5Sespie@noindent
462c87b03e5Sespiewill produce output @code{"a"} regardless of what the argument @var{a} is.
463c87b03e5Sespie
464c87b03e5Sespie@cindex @code{setjmp} incompatibilities
465c87b03e5Sespie@cindex @code{longjmp} incompatibilities
466c87b03e5Sespie@item
467c87b03e5SespieWhen you use @code{setjmp} and @code{longjmp}, the only automatic
468c87b03e5Sespievariables guaranteed to remain valid are those declared
469c87b03e5Sespie@code{volatile}.  This is a consequence of automatic register
470c87b03e5Sespieallocation.  Consider this function:
471c87b03e5Sespie
472c87b03e5Sespie@example
473c87b03e5Sespiejmp_buf j;
474c87b03e5Sespie
475c87b03e5Sespiefoo ()
476c87b03e5Sespie@{
477c87b03e5Sespie  int a, b;
478c87b03e5Sespie
479c87b03e5Sespie  a = fun1 ();
480c87b03e5Sespie  if (setjmp (j))
481c87b03e5Sespie    return a;
482c87b03e5Sespie
483c87b03e5Sespie  a = fun2 ();
484c87b03e5Sespie  /* @r{@code{longjmp (j)} may occur in @code{fun3}.} */
485c87b03e5Sespie  return a + fun3 ();
486c87b03e5Sespie@}
487c87b03e5Sespie@end example
488c87b03e5Sespie
489c87b03e5SespieHere @code{a} may or may not be restored to its first value when the
490c87b03e5Sespie@code{longjmp} occurs.  If @code{a} is allocated in a register, then
491c87b03e5Sespieits first value is restored; otherwise, it keeps the last value stored
492c87b03e5Sespiein it.
493c87b03e5Sespie
494c87b03e5Sespie@opindex W
495c87b03e5SespieIf you use the @option{-W} option with the @option{-O} option, you will
496c87b03e5Sespieget a warning when GCC thinks such a problem might be possible.
497c87b03e5Sespie
498c87b03e5Sespie@item
499c87b03e5SespiePrograms that use preprocessing directives in the middle of macro
500c87b03e5Sespiearguments do not work with GCC@.  For example, a program like this
501c87b03e5Sespiewill not work:
502c87b03e5Sespie
503c87b03e5Sespie@example
504c87b03e5Sespie@group
505c87b03e5Sespiefoobar (
506c87b03e5Sespie#define luser
507c87b03e5Sespie        hack)
508c87b03e5Sespie@end group
509c87b03e5Sespie@end example
510c87b03e5Sespie
511c87b03e5SespieISO C does not permit such a construct.
512c87b03e5Sespie
513c87b03e5Sespie@item
514c87b03e5SespieK&R compilers allow comments to cross over an inclusion boundary
515c87b03e5Sespie(i.e.@: started in an include file and ended in the including file).  I think
516c87b03e5Sespiethis would be quite ugly and can't imagine it could be needed.
517c87b03e5Sespie
518c87b03e5Sespie@cindex external declaration scope
519c87b03e5Sespie@cindex scope of external declarations
520c87b03e5Sespie@cindex declaration scope
521c87b03e5Sespie@item
522c87b03e5SespieDeclarations of external variables and functions within a block apply
523c87b03e5Sespieonly to the block containing the declaration.  In other words, they
524c87b03e5Sespiehave the same scope as any other declaration in the same place.
525c87b03e5Sespie
526c87b03e5SespieIn some other C compilers, a @code{extern} declaration affects all the
527c87b03e5Sespierest of the file even if it happens within a block.
528c87b03e5Sespie
529c87b03e5Sespie@item
530c87b03e5SespieIn traditional C, you can combine @code{long}, etc., with a typedef name,
531c87b03e5Sespieas shown here:
532c87b03e5Sespie
533c87b03e5Sespie@example
534c87b03e5Sespietypedef int foo;
535c87b03e5Sespietypedef long foo bar;
536c87b03e5Sespie@end example
537c87b03e5Sespie
538c87b03e5SespieIn ISO C, this is not allowed: @code{long} and other type modifiers
539c87b03e5Sespierequire an explicit @code{int}.
540c87b03e5Sespie
541c87b03e5Sespie@cindex typedef names as function parameters
542c87b03e5Sespie@item
543c87b03e5SespiePCC allows typedef names to be used as function parameters.
544c87b03e5Sespie
545c87b03e5Sespie@item
546c87b03e5SespieTraditional C allows the following erroneous pair of declarations to
547c87b03e5Sespieappear together in a given scope:
548c87b03e5Sespie
549c87b03e5Sespie@example
550c87b03e5Sespietypedef int foo;
551c87b03e5Sespietypedef foo foo;
552c87b03e5Sespie@end example
553c87b03e5Sespie
554c87b03e5Sespie@item
555c87b03e5SespieGCC treats all characters of identifiers as significant.  According to
556c87b03e5SespieK&R-1 (2.2), ``No more than the first eight characters are significant,
557c87b03e5Sespiealthough more may be used.''.  Also according to K&R-1 (2.2), ``An
558c87b03e5Sespieidentifier is a sequence of letters and digits; the first character must
559c87b03e5Sespiebe a letter.  The underscore _ counts as a letter.'', but GCC also
560c87b03e5Sespieallows dollar signs in identifiers.
561c87b03e5Sespie
562c87b03e5Sespie@cindex whitespace
563c87b03e5Sespie@item
564c87b03e5SespiePCC allows whitespace in the middle of compound assignment operators
565c87b03e5Sespiesuch as @samp{+=}.  GCC, following the ISO standard, does not
566c87b03e5Sespieallow this.
567c87b03e5Sespie
568c87b03e5Sespie@cindex apostrophes
569c87b03e5Sespie@cindex '
570c87b03e5Sespie@item
571c87b03e5SespieGCC complains about unterminated character constants inside of
572c87b03e5Sespiepreprocessing conditionals that fail.  Some programs have English
573c87b03e5Sespiecomments enclosed in conditionals that are guaranteed to fail; if these
574c87b03e5Sespiecomments contain apostrophes, GCC will probably report an error.  For
575c87b03e5Sespieexample, this code would produce an error:
576c87b03e5Sespie
577c87b03e5Sespie@example
578c87b03e5Sespie#if 0
579c87b03e5SespieYou can't expect this to work.
580c87b03e5Sespie#endif
581c87b03e5Sespie@end example
582c87b03e5Sespie
583c87b03e5SespieThe best solution to such a problem is to put the text into an actual
584c87b03e5SespieC comment delimited by @samp{/*@dots{}*/}.
585c87b03e5Sespie
586c87b03e5Sespie@item
587c87b03e5SespieMany user programs contain the declaration @samp{long time ();}.  In the
588c87b03e5Sespiepast, the system header files on many systems did not actually declare
589c87b03e5Sespie@code{time}, so it did not matter what type your program declared it to
590c87b03e5Sespiereturn.  But in systems with ISO C headers, @code{time} is declared to
591c87b03e5Sespiereturn @code{time_t}, and if that is not the same as @code{long}, then
592c87b03e5Sespie@samp{long time ();} is erroneous.
593c87b03e5Sespie
594c87b03e5SespieThe solution is to change your program to use appropriate system headers
595c87b03e5Sespie(@code{<time.h>} on systems with ISO C headers) and not to declare
596c87b03e5Sespie@code{time} if the system header files declare it, or failing that to
597c87b03e5Sespieuse @code{time_t} as the return type of @code{time}.
598c87b03e5Sespie
599c87b03e5Sespie@cindex @code{float} as function value type
600c87b03e5Sespie@item
601c87b03e5SespieWhen compiling functions that return @code{float}, PCC converts it to
602c87b03e5Sespiea double.  GCC actually returns a @code{float}.  If you are concerned
603c87b03e5Sespiewith PCC compatibility, you should declare your functions to return
604c87b03e5Sespie@code{double}; you might as well say what you mean.
605c87b03e5Sespie
606c87b03e5Sespie@cindex structures
607c87b03e5Sespie@cindex unions
608c87b03e5Sespie@item
609c87b03e5SespieWhen compiling functions that return structures or unions, GCC
610c87b03e5Sespieoutput code normally uses a method different from that used on most
611c87b03e5Sespieversions of Unix.  As a result, code compiled with GCC cannot call
612c87b03e5Sespiea structure-returning function compiled with PCC, and vice versa.
613c87b03e5Sespie
614c87b03e5SespieThe method used by GCC is as follows: a structure or union which is
615c87b03e5Sespie1, 2, 4 or 8 bytes long is returned like a scalar.  A structure or union
616c87b03e5Sespiewith any other size is stored into an address supplied by the caller
617c87b03e5Sespie(usually in a special, fixed register, but on some machines it is passed
618c87b03e5Sespieon the stack).  The machine-description macros @code{STRUCT_VALUE} and
619c87b03e5Sespie@code{STRUCT_INCOMING_VALUE} tell GCC where to pass this address.
620c87b03e5Sespie
621c87b03e5SespieBy contrast, PCC on most target machines returns structures and unions
622c87b03e5Sespieof any size by copying the data into an area of static storage, and then
623c87b03e5Sespiereturning the address of that storage as if it were a pointer value.
624c87b03e5SespieThe caller must copy the data from that memory area to the place where
625c87b03e5Sespiethe value is wanted.  GCC does not use this method because it is
626c87b03e5Sespieslower and nonreentrant.
627c87b03e5Sespie
628c87b03e5SespieOn some newer machines, PCC uses a reentrant convention for all
629c87b03e5Sespiestructure and union returning.  GCC on most of these machines uses a
630c87b03e5Sespiecompatible convention when returning structures and unions in memory,
631c87b03e5Sespiebut still returns small structures and unions in registers.
632c87b03e5Sespie
633c87b03e5Sespie@opindex fpcc-struct-return
634c87b03e5SespieYou can tell GCC to use a compatible convention for all structure and
635c87b03e5Sespieunion returning with the option @option{-fpcc-struct-return}.
636c87b03e5Sespie
637c87b03e5Sespie@cindex preprocessing tokens
638c87b03e5Sespie@cindex preprocessing numbers
639c87b03e5Sespie@item
640c87b03e5SespieGCC complains about program fragments such as @samp{0x74ae-0x4000}
641c87b03e5Sespiewhich appear to be two hexadecimal constants separated by the minus
642c87b03e5Sespieoperator.  Actually, this string is a single @dfn{preprocessing token}.
643c87b03e5SespieEach such token must correspond to one token in C@.  Since this does not,
644c87b03e5SespieGCC prints an error message.  Although it may appear obvious that what
645c87b03e5Sespieis meant is an operator and two values, the ISO C standard specifically
646c87b03e5Sespierequires that this be treated as erroneous.
647c87b03e5Sespie
648c87b03e5SespieA @dfn{preprocessing token} is a @dfn{preprocessing number} if it
649c87b03e5Sespiebegins with a digit and is followed by letters, underscores, digits,
650c87b03e5Sespieperiods and @samp{e+}, @samp{e-}, @samp{E+}, @samp{E-}, @samp{p+},
651c87b03e5Sespie@samp{p-}, @samp{P+}, or @samp{P-} character sequences.  (In strict C89
652c87b03e5Sespiemode, the sequences @samp{p+}, @samp{p-}, @samp{P+} and @samp{P-} cannot
653c87b03e5Sespieappear in preprocessing numbers.)
654c87b03e5Sespie
655c87b03e5SespieTo make the above program fragment valid, place whitespace in front of
656c87b03e5Sespiethe minus sign.  This whitespace will end the preprocessing number.
657c87b03e5Sespie@end itemize
658c87b03e5Sespie
659c87b03e5Sespie@node Fixed Headers
660c87b03e5Sespie@section Fixed Header Files
661c87b03e5Sespie
662c87b03e5SespieGCC needs to install corrected versions of some system header files.
663c87b03e5SespieThis is because most target systems have some header files that won't
664c87b03e5Sespiework with GCC unless they are changed.  Some have bugs, some are
665c87b03e5Sespieincompatible with ISO C, and some depend on special features of other
666c87b03e5Sespiecompilers.
667c87b03e5Sespie
668c87b03e5SespieInstalling GCC automatically creates and installs the fixed header
669c87b03e5Sespiefiles, by running a program called @code{fixincludes} (or for certain
670c87b03e5Sespietargets an alternative such as @code{fixinc.svr4}).  Normally, you
671c87b03e5Sespiedon't need to pay attention to this.  But there are cases where it
672c87b03e5Sespiedoesn't do the right thing automatically.
673c87b03e5Sespie
674c87b03e5Sespie@itemize @bullet
675c87b03e5Sespie@item
676c87b03e5SespieIf you update the system's header files, such as by installing a new
677c87b03e5Sespiesystem version, the fixed header files of GCC are not automatically
678c87b03e5Sespieupdated.  The easiest way to update them is to reinstall GCC@.  (If
679c87b03e5Sespieyou want to be clever, look in the makefile and you can find a
680c87b03e5Sespieshortcut.)
681c87b03e5Sespie
682c87b03e5Sespie@item
683c87b03e5SespieOn some systems, in particular SunOS 4, header file directories contain
684c87b03e5Sespiemachine-specific symbolic links in certain places.  This makes it
685c87b03e5Sespiepossible to share most of the header files among hosts running the
686c87b03e5Sespiesame version of SunOS 4 on different machine models.
687c87b03e5Sespie
688c87b03e5SespieThe programs that fix the header files do not understand this special
689c87b03e5Sespieway of using symbolic links; therefore, the directory of fixed header
690c87b03e5Sespiefiles is good only for the machine model used to build it.
691c87b03e5Sespie
692c87b03e5SespieIn SunOS 4, only programs that look inside the kernel will notice the
693c87b03e5Sespiedifference between machine models.  Therefore, for most purposes, you
694c87b03e5Sespieneed not be concerned about this.
695c87b03e5Sespie
696c87b03e5SespieIt is possible to make separate sets of fixed header files for the
697c87b03e5Sespiedifferent machine models, and arrange a structure of symbolic links so
698c87b03e5Sespieas to use the proper set, but you'll have to do this by hand.
699c87b03e5Sespie
700c87b03e5Sespie@item
701c87b03e5SespieOn Lynxos, GCC by default does not fix the header files.  This is
702c87b03e5Sespiebecause bugs in the shell cause the @code{fixincludes} script to fail.
703c87b03e5Sespie
704c87b03e5SespieThis means you will encounter problems due to bugs in the system header
705c87b03e5Sespiefiles.  It may be no comfort that they aren't GCC's fault, but it
706c87b03e5Sespiedoes mean that there's nothing for us to do about them.
707c87b03e5Sespie@end itemize
708c87b03e5Sespie
709c87b03e5Sespie@node Standard Libraries
710c87b03e5Sespie@section Standard Libraries
711c87b03e5Sespie
712c87b03e5Sespie@opindex Wall
713c87b03e5SespieGCC by itself attempts to be a conforming freestanding implementation.
714c87b03e5Sespie@xref{Standards,,Language Standards Supported by GCC}, for details of
715c87b03e5Sespiewhat this means.  Beyond the library facilities required of such an
716c87b03e5Sespieimplementation, the rest of the C library is supplied by the vendor of
717c87b03e5Sespiethe operating system.  If that C library doesn't conform to the C
718c87b03e5Sespiestandards, then your programs might get warnings (especially when using
719c87b03e5Sespie@option{-Wall}) that you don't expect.
720c87b03e5Sespie
721c87b03e5SespieFor example, the @code{sprintf} function on SunOS 4.1.3 returns
722c87b03e5Sespie@code{char *} while the C standard says that @code{sprintf} returns an
723c87b03e5Sespie@code{int}.  The @code{fixincludes} program could make the prototype for
724c87b03e5Sespiethis function match the Standard, but that would be wrong, since the
725c87b03e5Sespiefunction will still return @code{char *}.
726c87b03e5Sespie
727c87b03e5SespieIf you need a Standard compliant library, then you need to find one, as
728c87b03e5SespieGCC does not provide one.  The GNU C library (called @code{glibc})
729c87b03e5Sespieprovides ISO C, POSIX, BSD, SystemV and X/Open compatibility for
730c87b03e5SespieGNU/Linux and HURD-based GNU systems; no recent version of it supports
731c87b03e5Sespieother systems, though some very old versions did.  Version 2.2 of the
732c87b03e5SespieGNU C library includes nearly complete C99 support.  You could also ask
733c87b03e5Sespieyour operating system vendor if newer libraries are available.
734c87b03e5Sespie
735c87b03e5Sespie@node Disappointments
736c87b03e5Sespie@section Disappointments and Misunderstandings
737c87b03e5Sespie
738c87b03e5SespieThese problems are perhaps regrettable, but we don't know any practical
739c87b03e5Sespieway around them.
740c87b03e5Sespie
741c87b03e5Sespie@itemize @bullet
742c87b03e5Sespie@item
743c87b03e5SespieCertain local variables aren't recognized by debuggers when you compile
744c87b03e5Sespiewith optimization.
745c87b03e5Sespie
746c87b03e5SespieThis occurs because sometimes GCC optimizes the variable out of
747c87b03e5Sespieexistence.  There is no way to tell the debugger how to compute the
748c87b03e5Sespievalue such a variable ``would have had'', and it is not clear that would
749c87b03e5Sespiebe desirable anyway.  So GCC simply does not mention the eliminated
750c87b03e5Sespievariable when it writes debugging information.
751c87b03e5Sespie
752c87b03e5SespieYou have to expect a certain amount of disagreement between the
753c87b03e5Sespieexecutable and your source code, when you use optimization.
754c87b03e5Sespie
755c87b03e5Sespie@cindex conflicting types
756c87b03e5Sespie@cindex scope of declaration
757c87b03e5Sespie@item
758c87b03e5SespieUsers often think it is a bug when GCC reports an error for code
759c87b03e5Sespielike this:
760c87b03e5Sespie
761c87b03e5Sespie@example
762c87b03e5Sespieint foo (struct mumble *);
763c87b03e5Sespie
764c87b03e5Sespiestruct mumble @{ @dots{} @};
765c87b03e5Sespie
766c87b03e5Sespieint foo (struct mumble *x)
767c87b03e5Sespie@{ @dots{} @}
768c87b03e5Sespie@end example
769c87b03e5Sespie
770c87b03e5SespieThis code really is erroneous, because the scope of @code{struct
771c87b03e5Sespiemumble} in the prototype is limited to the argument list containing it.
772c87b03e5SespieIt does not refer to the @code{struct mumble} defined with file scope
773c87b03e5Sespieimmediately below---they are two unrelated types with similar names in
774c87b03e5Sespiedifferent scopes.
775c87b03e5Sespie
776c87b03e5SespieBut in the definition of @code{foo}, the file-scope type is used
777c87b03e5Sespiebecause that is available to be inherited.  Thus, the definition and
778c87b03e5Sespiethe prototype do not match, and you get an error.
779c87b03e5Sespie
780c87b03e5SespieThis behavior may seem silly, but it's what the ISO standard specifies.
781c87b03e5SespieIt is easy enough for you to make your code work by moving the
782c87b03e5Sespiedefinition of @code{struct mumble} above the prototype.  It's not worth
783c87b03e5Sespiebeing incompatible with ISO C just to avoid an error for the example
784c87b03e5Sespieshown above.
785c87b03e5Sespie
786c87b03e5Sespie@item
787c87b03e5SespieAccesses to bit-fields even in volatile objects works by accessing larger
788c87b03e5Sespieobjects, such as a byte or a word.  You cannot rely on what size of
789c87b03e5Sespieobject is accessed in order to read or write the bit-field; it may even
790c87b03e5Sespievary for a given bit-field according to the precise usage.
791c87b03e5Sespie
792c87b03e5SespieIf you care about controlling the amount of memory that is accessed, use
793c87b03e5Sespievolatile but do not use bit-fields.
794c87b03e5Sespie
795c87b03e5Sespie@item
796c87b03e5SespieGCC comes with shell scripts to fix certain known problems in system
797c87b03e5Sespieheader files.  They install corrected copies of various header files in
798c87b03e5Sespiea special directory where only GCC will normally look for them.  The
799c87b03e5Sespiescripts adapt to various systems by searching all the system header
800c87b03e5Sespiefiles for the problem cases that we know about.
801c87b03e5Sespie
802c87b03e5SespieIf new system header files are installed, nothing automatically arranges
803c87b03e5Sespieto update the corrected header files.  You will have to reinstall GCC
804c87b03e5Sespieto fix the new header files.  More specifically, go to the build
805c87b03e5Sespiedirectory and delete the files @file{stmp-fixinc} and
806c87b03e5Sespie@file{stmp-headers}, and the subdirectory @code{include}; then do
807c87b03e5Sespie@samp{make install} again.
808c87b03e5Sespie
809c87b03e5Sespie@item
810c87b03e5Sespie@cindex floating point precision
811c87b03e5SespieOn 68000 and x86 systems, for instance, you can get paradoxical results
812c87b03e5Sespieif you test the precise values of floating point numbers.  For example,
813c87b03e5Sespieyou can find that a floating point value which is not a NaN is not equal
814c87b03e5Sespieto itself.  This results from the fact that the floating point registers
815c87b03e5Sespiehold a few more bits of precision than fit in a @code{double} in memory.
816c87b03e5SespieCompiled code moves values between memory and floating point registers
817c87b03e5Sespieat its convenience, and moving them into memory truncates them.
818c87b03e5Sespie
819c87b03e5Sespie@opindex ffloat-store
820c87b03e5SespieYou can partially avoid this problem by using the @option{-ffloat-store}
821c87b03e5Sespieoption (@pxref{Optimize Options}).
822c87b03e5Sespie
823c87b03e5Sespie@item
824c87b03e5SespieOn AIX and other platforms without weak symbol support, templates
825c87b03e5Sespieneed to be instantiated explicitly and symbols for static members
826c87b03e5Sespieof templates will not be generated.
827c87b03e5Sespie
828c87b03e5Sespie@item
829c87b03e5SespieOn AIX, GCC scans object files and library archives for static
830c87b03e5Sespieconstructors and destructors when linking an application before the
831c87b03e5Sespielinker prunes unreferenced symbols.  This is necessary to prevent the
832c87b03e5SespieAIX linker from mistakenly assuming that static constructor or
833c87b03e5Sespiedestructor are unused and removing them before the scanning can occur.
834c87b03e5SespieAll static constructors and destructors found will be referenced even
835c87b03e5Sespiethough the modules in which they occur may not be used by the program.
836c87b03e5SespieThis may lead to both increased executable size and unexpected symbol
837c87b03e5Sespiereferences.
838c87b03e5Sespie@end itemize
839c87b03e5Sespie
840c87b03e5Sespie@node C++ Misunderstandings
841c87b03e5Sespie@section Common Misunderstandings with GNU C++
842c87b03e5Sespie
843c87b03e5Sespie@cindex misunderstandings in C++
844c87b03e5Sespie@cindex surprises in C++
845c87b03e5Sespie@cindex C++ misunderstandings
846c87b03e5SespieC++ is a complex language and an evolving one, and its standard
847c87b03e5Sespiedefinition (the ISO C++ standard) was only recently completed.  As a
848c87b03e5Sespieresult, your C++ compiler may occasionally surprise you, even when its
849c87b03e5Sespiebehavior is correct.  This section discusses some areas that frequently
850c87b03e5Sespiegive rise to questions of this sort.
851c87b03e5Sespie
852c87b03e5Sespie@menu
853c87b03e5Sespie* Static Definitions::  Static member declarations are not definitions
854c87b03e5Sespie* Temporaries::         Temporaries may vanish before you expect
855c87b03e5Sespie* Copy Assignment::     Copy Assignment operators copy virtual bases twice
856c87b03e5Sespie@end menu
857c87b03e5Sespie
858c87b03e5Sespie@node Static Definitions
859c87b03e5Sespie@subsection Declare @emph{and} Define Static Members
860c87b03e5Sespie
861c87b03e5Sespie@cindex C++ static data, declaring and defining
862c87b03e5Sespie@cindex static data in C++, declaring and defining
863c87b03e5Sespie@cindex declaring static data in C++
864c87b03e5Sespie@cindex defining static data in C++
865c87b03e5SespieWhen a class has static data members, it is not enough to @emph{declare}
866c87b03e5Sespiethe static member; you must also @emph{define} it.  For example:
867c87b03e5Sespie
868c87b03e5Sespie@example
869c87b03e5Sespieclass Foo
870c87b03e5Sespie@{
871c87b03e5Sespie  @dots{}
872c87b03e5Sespie  void method();
873c87b03e5Sespie  static int bar;
874c87b03e5Sespie@};
875c87b03e5Sespie@end example
876c87b03e5Sespie
877c87b03e5SespieThis declaration only establishes that the class @code{Foo} has an
878c87b03e5Sespie@code{int} named @code{Foo::bar}, and a member function named
879c87b03e5Sespie@code{Foo::method}.  But you still need to define @emph{both}
880c87b03e5Sespie@code{method} and @code{bar} elsewhere.  According to the ISO
881c87b03e5Sespiestandard, you must supply an initializer in one (and only one) source
882c87b03e5Sespiefile, such as:
883c87b03e5Sespie
884c87b03e5Sespie@example
885c87b03e5Sespieint Foo::bar = 0;
886c87b03e5Sespie@end example
887c87b03e5Sespie
888c87b03e5SespieOther C++ compilers may not correctly implement the standard behavior.
889c87b03e5SespieAs a result, when you switch to @command{g++} from one of these compilers,
890c87b03e5Sespieyou may discover that a program that appeared to work correctly in fact
891c87b03e5Sespiedoes not conform to the standard: @command{g++} reports as undefined
892c87b03e5Sespiesymbols any static data members that lack definitions.
893c87b03e5Sespie
894c87b03e5Sespie@node Temporaries
895c87b03e5Sespie@subsection Temporaries May Vanish Before You Expect
896c87b03e5Sespie
897c87b03e5Sespie@cindex temporaries, lifetime of
898c87b03e5Sespie@cindex portions of temporary objects, pointers to
899c87b03e5SespieIt is dangerous to use pointers or references to @emph{portions} of a
900c87b03e5Sespietemporary object.  The compiler may very well delete the object before
901c87b03e5Sespieyou expect it to, leaving a pointer to garbage.  The most common place
902c87b03e5Sespiewhere this problem crops up is in classes like string classes,
903c87b03e5Sespieespecially ones that define a conversion function to type @code{char *}
904c87b03e5Sespieor @code{const char *}---which is one reason why the standard
905c87b03e5Sespie@code{string} class requires you to call the @code{c_str} member
906c87b03e5Sespiefunction.  However, any class that returns a pointer to some internal
907c87b03e5Sespiestructure is potentially subject to this problem.
908c87b03e5Sespie
909c87b03e5SespieFor example, a program may use a function @code{strfunc} that returns
910c87b03e5Sespie@code{string} objects, and another function @code{charfunc} that
911c87b03e5Sespieoperates on pointers to @code{char}:
912c87b03e5Sespie
913c87b03e5Sespie@example
914c87b03e5Sespiestring strfunc ();
915c87b03e5Sespievoid charfunc (const char *);
916c87b03e5Sespie
917c87b03e5Sespievoid
918c87b03e5Sespief ()
919c87b03e5Sespie@{
920c87b03e5Sespie  const char *p = strfunc().c_str();
921c87b03e5Sespie  @dots{}
922c87b03e5Sespie  charfunc (p);
923c87b03e5Sespie  @dots{}
924c87b03e5Sespie  charfunc (p);
925c87b03e5Sespie@}
926c87b03e5Sespie@end example
927c87b03e5Sespie
928c87b03e5Sespie@noindent
929c87b03e5SespieIn this situation, it may seem reasonable to save a pointer to the C
930c87b03e5Sespiestring returned by the @code{c_str} member function and use that rather
931c87b03e5Sespiethan call @code{c_str} repeatedly.  However, the temporary string
932c87b03e5Sespiecreated by the call to @code{strfunc} is destroyed after @code{p} is
933c87b03e5Sespieinitialized, at which point @code{p} is left pointing to freed memory.
934c87b03e5Sespie
935c87b03e5SespieCode like this may run successfully under some other compilers,
936c87b03e5Sespieparticularly obsolete cfront-based compilers that delete temporaries
937c87b03e5Sespiealong with normal local variables.  However, the GNU C++ behavior is
938c87b03e5Sespiestandard-conforming, so if your program depends on late destruction of
939c87b03e5Sespietemporaries it is not portable.
940c87b03e5Sespie
941c87b03e5SespieThe safe way to write such code is to give the temporary a name, which
942c87b03e5Sespieforces it to remain until the end of the scope of the name.  For
943c87b03e5Sespieexample:
944c87b03e5Sespie
945c87b03e5Sespie@example
946*4e43c760Sespieconst string& tmp = strfunc ();
947c87b03e5Sespiecharfunc (tmp.c_str ());
948c87b03e5Sespie@end example
949c87b03e5Sespie
950c87b03e5Sespie@node Copy Assignment
951c87b03e5Sespie@subsection Implicit Copy-Assignment for Virtual Bases
952c87b03e5Sespie
953c87b03e5SespieWhen a base class is virtual, only one subobject of the base class
954c87b03e5Sespiebelongs to each full object.  Also, the constructors and destructors are
955c87b03e5Sespieinvoked only once, and called from the most-derived class.  However, such
956c87b03e5Sespieobjects behave unspecified when being assigned.  For example:
957c87b03e5Sespie
958c87b03e5Sespie@example
959c87b03e5Sespiestruct Base@{
960c87b03e5Sespie  char *name;
961c87b03e5Sespie  Base(char *n) : name(strdup(n))@{@}
962c87b03e5Sespie  Base& operator= (const Base& other)@{
963c87b03e5Sespie   free (name);
964c87b03e5Sespie   name = strdup (other.name);
965c87b03e5Sespie  @}
966c87b03e5Sespie@};
967c87b03e5Sespie
968c87b03e5Sespiestruct A:virtual Base@{
969c87b03e5Sespie  int val;
970c87b03e5Sespie  A():Base("A")@{@}
971c87b03e5Sespie@};
972c87b03e5Sespie
973c87b03e5Sespiestruct B:virtual Base@{
974c87b03e5Sespie  int bval;
975c87b03e5Sespie  B():Base("B")@{@}
976c87b03e5Sespie@};
977c87b03e5Sespie
978c87b03e5Sespiestruct Derived:public A, public B@{
979c87b03e5Sespie  Derived():Base("Derived")@{@}
980c87b03e5Sespie@};
981c87b03e5Sespie
982c87b03e5Sespievoid func(Derived &d1, Derived &d2)
983c87b03e5Sespie@{
984c87b03e5Sespie  d1 = d2;
985c87b03e5Sespie@}
986c87b03e5Sespie@end example
987c87b03e5Sespie
988c87b03e5SespieThe C++ standard specifies that @samp{Base::Base} is only called once
989c87b03e5Sespiewhen constructing or copy-constructing a Derived object.  It is
990c87b03e5Sespieunspecified whether @samp{Base::operator=} is called more than once when
991c87b03e5Sespiethe implicit copy-assignment for Derived objects is invoked (as it is
992c87b03e5Sespieinside @samp{func} in the example).
993c87b03e5Sespie
994c87b03e5Sespieg++ implements the ``intuitive'' algorithm for copy-assignment: assign all
995c87b03e5Sespiedirect bases, then assign all members.  In that algorithm, the virtual
996c87b03e5Sespiebase subobject can be encountered more than once.  In the example, copying
997c87b03e5Sespieproceeds in the following order: @samp{val}, @samp{name} (via
998c87b03e5Sespie@code{strdup}), @samp{bval}, and @samp{name} again.
999c87b03e5Sespie
1000c87b03e5SespieIf application code relies on copy-assignment, a user-defined
1001c87b03e5Sespiecopy-assignment operator removes any uncertainties.  With such an
1002c87b03e5Sespieoperator, the application can define whether and how the virtual base
1003c87b03e5Sespiesubobject is assigned.
1004c87b03e5Sespie
1005c87b03e5Sespie@node Protoize Caveats
1006c87b03e5Sespie@section Caveats of using @command{protoize}
1007c87b03e5Sespie
1008c87b03e5SespieThe conversion programs @command{protoize} and @command{unprotoize} can
1009c87b03e5Sespiesometimes change a source file in a way that won't work unless you
1010c87b03e5Sespierearrange it.
1011c87b03e5Sespie
1012c87b03e5Sespie@itemize @bullet
1013c87b03e5Sespie@item
1014c87b03e5Sespie@command{protoize} can insert references to a type name or type tag before
1015c87b03e5Sespiethe definition, or in a file where they are not defined.
1016c87b03e5Sespie
1017c87b03e5SespieIf this happens, compiler error messages should show you where the new
1018c87b03e5Sespiereferences are, so fixing the file by hand is straightforward.
1019c87b03e5Sespie
1020c87b03e5Sespie@item
1021c87b03e5SespieThere are some C constructs which @command{protoize} cannot figure out.
1022c87b03e5SespieFor example, it can't determine argument types for declaring a
1023c87b03e5Sespiepointer-to-function variable; this you must do by hand.  @command{protoize}
1024c87b03e5Sespieinserts a comment containing @samp{???} each time it finds such a
1025c87b03e5Sespievariable; so you can find all such variables by searching for this
1026c87b03e5Sespiestring.  ISO C does not require declaring the argument types of
1027c87b03e5Sespiepointer-to-function types.
1028c87b03e5Sespie
1029c87b03e5Sespie@item
1030c87b03e5SespieUsing @command{unprotoize} can easily introduce bugs.  If the program
1031c87b03e5Sespierelied on prototypes to bring about conversion of arguments, these
1032c87b03e5Sespieconversions will not take place in the program without prototypes.
1033c87b03e5SespieOne case in which you can be sure @command{unprotoize} is safe is when
1034c87b03e5Sespieyou are removing prototypes that were made with @command{protoize}; if
1035c87b03e5Sespiethe program worked before without any prototypes, it will work again
1036c87b03e5Sespiewithout them.
1037c87b03e5Sespie
1038c87b03e5Sespie@opindex Wconversion
1039c87b03e5SespieYou can find all the places where this problem might occur by compiling
1040c87b03e5Sespiethe program with the @option{-Wconversion} option.  It prints a warning
1041c87b03e5Sespiewhenever an argument is converted.
1042c87b03e5Sespie
1043c87b03e5Sespie@item
1044c87b03e5SespieBoth conversion programs can be confused if there are macro calls in and
1045c87b03e5Sespiearound the text to be converted.  In other words, the standard syntax
1046c87b03e5Sespiefor a declaration or definition must not result from expanding a macro.
1047c87b03e5SespieThis problem is inherent in the design of C and cannot be fixed.  If
1048c87b03e5Sespieonly a few functions have confusing macro calls, you can easily convert
1049c87b03e5Sespiethem manually.
1050c87b03e5Sespie
1051c87b03e5Sespie@item
1052c87b03e5Sespie@command{protoize} cannot get the argument types for a function whose
1053c87b03e5Sespiedefinition was not actually compiled due to preprocessing conditionals.
1054c87b03e5SespieWhen this happens, @command{protoize} changes nothing in regard to such
1055c87b03e5Sespiea function.  @command{protoize} tries to detect such instances and warn
1056c87b03e5Sespieabout them.
1057c87b03e5Sespie
1058c87b03e5SespieYou can generally work around this problem by using @command{protoize} step
1059c87b03e5Sespieby step, each time specifying a different set of @option{-D} options for
1060c87b03e5Sespiecompilation, until all of the functions have been converted.  There is
1061c87b03e5Sespieno automatic way to verify that you have got them all, however.
1062c87b03e5Sespie
1063c87b03e5Sespie@item
1064c87b03e5SespieConfusion may result if there is an occasion to convert a function
1065c87b03e5Sespiedeclaration or definition in a region of source code where there is more
1066c87b03e5Sespiethan one formal parameter list present.  Thus, attempts to convert code
1067c87b03e5Sespiecontaining multiple (conditionally compiled) versions of a single
1068c87b03e5Sespiefunction header (in the same vicinity) may not produce the desired (or
1069c87b03e5Sespieexpected) results.
1070c87b03e5Sespie
1071c87b03e5SespieIf you plan on converting source files which contain such code, it is
1072c87b03e5Sespierecommended that you first make sure that each conditionally compiled
1073c87b03e5Sespieregion of source code which contains an alternative function header also
1074c87b03e5Sespiecontains at least one additional follower token (past the final right
1075c87b03e5Sespieparenthesis of the function header).  This should circumvent the
1076c87b03e5Sespieproblem.
1077c87b03e5Sespie
1078c87b03e5Sespie@item
1079c87b03e5Sespie@command{unprotoize} can become confused when trying to convert a function
1080c87b03e5Sespiedefinition or declaration which contains a declaration for a
1081c87b03e5Sespiepointer-to-function formal argument which has the same name as the
1082c87b03e5Sespiefunction being defined or declared.  We recommend you avoid such choices
1083c87b03e5Sespieof formal parameter names.
1084c87b03e5Sespie
1085c87b03e5Sespie@item
1086c87b03e5SespieYou might also want to correct some of the indentation by hand and break
1087c87b03e5Sespielong lines.  (The conversion programs don't write lines longer than
1088c87b03e5Sespieeighty characters in any case.)
1089c87b03e5Sespie@end itemize
1090c87b03e5Sespie
1091c87b03e5Sespie@node Non-bugs
1092c87b03e5Sespie@section Certain Changes We Don't Want to Make
1093c87b03e5Sespie
1094c87b03e5SespieThis section lists changes that people frequently request, but which
1095c87b03e5Sespiewe do not make because we think GCC is better without them.
1096c87b03e5Sespie
1097c87b03e5Sespie@itemize @bullet
1098c87b03e5Sespie@item
1099c87b03e5SespieChecking the number and type of arguments to a function which has an
1100c87b03e5Sespieold-fashioned definition and no prototype.
1101c87b03e5Sespie
1102c87b03e5SespieSuch a feature would work only occasionally---only for calls that appear
1103c87b03e5Sespiein the same file as the called function, following the definition.  The
1104c87b03e5Sespieonly way to check all calls reliably is to add a prototype for the
1105c87b03e5Sespiefunction.  But adding a prototype eliminates the motivation for this
1106c87b03e5Sespiefeature.  So the feature is not worthwhile.
1107c87b03e5Sespie
1108c87b03e5Sespie@item
1109c87b03e5SespieWarning about using an expression whose type is signed as a shift count.
1110c87b03e5Sespie
1111c87b03e5SespieShift count operands are probably signed more often than unsigned.
1112c87b03e5SespieWarning about this would cause far more annoyance than good.
1113c87b03e5Sespie
1114c87b03e5Sespie@item
1115c87b03e5SespieWarning about assigning a signed value to an unsigned variable.
1116c87b03e5Sespie
1117c87b03e5SespieSuch assignments must be very common; warning about them would cause
1118c87b03e5Sespiemore annoyance than good.
1119c87b03e5Sespie
1120c87b03e5Sespie@item
1121c87b03e5SespieWarning when a non-void function value is ignored.
1122c87b03e5Sespie
1123c87b03e5SespieComing as I do from a Lisp background, I balk at the idea that there is
1124c87b03e5Sespiesomething dangerous about discarding a value.  There are functions that
1125c87b03e5Sespiereturn values which some callers may find useful; it makes no sense to
1126c87b03e5Sespieclutter the program with a cast to @code{void} whenever the value isn't
1127c87b03e5Sespieuseful.
1128c87b03e5Sespie
1129c87b03e5Sespie@item
1130c87b03e5Sespie@opindex fshort-enums
1131c87b03e5SespieMaking @option{-fshort-enums} the default.
1132c87b03e5Sespie
1133c87b03e5SespieThis would cause storage layout to be incompatible with most other C
1134c87b03e5Sespiecompilers.  And it doesn't seem very important, given that you can get
1135c87b03e5Sespiethe same result in other ways.  The case where it matters most is when
1136c87b03e5Sespiethe enumeration-valued object is inside a structure, and in that case
1137c87b03e5Sespieyou can specify a field width explicitly.
1138c87b03e5Sespie
1139c87b03e5Sespie@item
1140c87b03e5SespieMaking bit-fields unsigned by default on particular machines where ``the
1141c87b03e5SespieABI standard'' says to do so.
1142c87b03e5Sespie
1143c87b03e5SespieThe ISO C standard leaves it up to the implementation whether a bit-field
1144c87b03e5Sespiedeclared plain @code{int} is signed or not.  This in effect creates two
1145c87b03e5Sespiealternative dialects of C@.
1146c87b03e5Sespie
1147c87b03e5Sespie@opindex fsigned-bitfields
1148c87b03e5Sespie@opindex funsigned-bitfields
1149c87b03e5SespieThe GNU C compiler supports both dialects; you can specify the signed
1150c87b03e5Sespiedialect with @option{-fsigned-bitfields} and the unsigned dialect with
1151c87b03e5Sespie@option{-funsigned-bitfields}.  However, this leaves open the question of
1152c87b03e5Sespiewhich dialect to use by default.
1153c87b03e5Sespie
1154c87b03e5SespieCurrently, the preferred dialect makes plain bit-fields signed, because
1155c87b03e5Sespiethis is simplest.  Since @code{int} is the same as @code{signed int} in
1156c87b03e5Sespieevery other context, it is cleanest for them to be the same in bit-fields
1157c87b03e5Sespieas well.
1158c87b03e5Sespie
1159c87b03e5SespieSome computer manufacturers have published Application Binary Interface
1160c87b03e5Sespiestandards which specify that plain bit-fields should be unsigned.  It is
1161c87b03e5Sespiea mistake, however, to say anything about this issue in an ABI@.  This is
1162c87b03e5Sespiebecause the handling of plain bit-fields distinguishes two dialects of C@.
1163c87b03e5SespieBoth dialects are meaningful on every type of machine.  Whether a
1164c87b03e5Sespieparticular object file was compiled using signed bit-fields or unsigned
1165c87b03e5Sespieis of no concern to other object files, even if they access the same
1166c87b03e5Sespiebit-fields in the same data structures.
1167c87b03e5Sespie
1168c87b03e5SespieA given program is written in one or the other of these two dialects.
1169c87b03e5SespieThe program stands a chance to work on most any machine if it is
1170c87b03e5Sespiecompiled with the proper dialect.  It is unlikely to work at all if
1171c87b03e5Sespiecompiled with the wrong dialect.
1172c87b03e5Sespie
1173c87b03e5SespieMany users appreciate the GNU C compiler because it provides an
1174c87b03e5Sespieenvironment that is uniform across machines.  These users would be
1175c87b03e5Sespieinconvenienced if the compiler treated plain bit-fields differently on
1176c87b03e5Sespiecertain machines.
1177c87b03e5Sespie
1178c87b03e5SespieOccasionally users write programs intended only for a particular machine
1179c87b03e5Sespietype.  On these occasions, the users would benefit if the GNU C compiler
1180c87b03e5Sespiewere to support by default the same dialect as the other compilers on
1181c87b03e5Sespiethat machine.  But such applications are rare.  And users writing a
1182c87b03e5Sespieprogram to run on more than one type of machine cannot possibly benefit
1183c87b03e5Sespiefrom this kind of compatibility.
1184c87b03e5Sespie
1185c87b03e5SespieThis is why GCC does and will treat plain bit-fields in the same
1186c87b03e5Sespiefashion on all types of machines (by default).
1187c87b03e5Sespie
1188c87b03e5SespieThere are some arguments for making bit-fields unsigned by default on all
1189c87b03e5Sespiemachines.  If, for example, this becomes a universal de facto standard,
1190c87b03e5Sespieit would make sense for GCC to go along with it.  This is something
1191c87b03e5Sespieto be considered in the future.
1192c87b03e5Sespie
1193c87b03e5Sespie(Of course, users strongly concerned about portability should indicate
1194c87b03e5Sespieexplicitly in each bit-field whether it is signed or not.  In this way,
1195c87b03e5Sespiethey write programs which have the same meaning in both C dialects.)
1196c87b03e5Sespie
1197c87b03e5Sespie@item
1198c87b03e5Sespie@opindex ansi
1199c87b03e5Sespie@opindex std
1200c87b03e5SespieUndefining @code{__STDC__} when @option{-ansi} is not used.
1201c87b03e5Sespie
1202c87b03e5SespieCurrently, GCC defines @code{__STDC__} unconditionally.  This provides
1203c87b03e5Sespiegood results in practice.
1204c87b03e5Sespie
1205c87b03e5SespieProgrammers normally use conditionals on @code{__STDC__} to ask whether
1206c87b03e5Sespieit is safe to use certain features of ISO C, such as function
1207c87b03e5Sespieprototypes or ISO token concatenation.  Since plain @command{gcc} supports
1208c87b03e5Sespieall the features of ISO C, the correct answer to these questions is
1209c87b03e5Sespie``yes''.
1210c87b03e5Sespie
1211c87b03e5SespieSome users try to use @code{__STDC__} to check for the availability of
1212c87b03e5Sespiecertain library facilities.  This is actually incorrect usage in an ISO
1213c87b03e5SespieC program, because the ISO C standard says that a conforming
1214c87b03e5Sespiefreestanding implementation should define @code{__STDC__} even though it
1215c87b03e5Sespiedoes not have the library facilities.  @samp{gcc -ansi -pedantic} is a
1216c87b03e5Sespieconforming freestanding implementation, and it is therefore required to
1217c87b03e5Sespiedefine @code{__STDC__}, even though it does not come with an ISO C
1218c87b03e5Sespielibrary.
1219c87b03e5Sespie
1220c87b03e5SespieSometimes people say that defining @code{__STDC__} in a compiler that
1221c87b03e5Sespiedoes not completely conform to the ISO C standard somehow violates the
1222c87b03e5Sespiestandard.  This is illogical.  The standard is a standard for compilers
1223c87b03e5Sespiethat claim to support ISO C, such as @samp{gcc -ansi}---not for other
1224c87b03e5Sespiecompilers such as plain @command{gcc}.  Whatever the ISO C standard says
1225c87b03e5Sespieis relevant to the design of plain @command{gcc} without @option{-ansi} only
1226c87b03e5Sespiefor pragmatic reasons, not as a requirement.
1227c87b03e5Sespie
1228c87b03e5SespieGCC normally defines @code{__STDC__} to be 1, and in addition
1229c87b03e5Sespiedefines @code{__STRICT_ANSI__} if you specify the @option{-ansi} option,
1230c87b03e5Sespieor a @option{-std} option for strict conformance to some version of ISO C@.
1231c87b03e5SespieOn some hosts, system include files use a different convention, where
1232c87b03e5Sespie@code{__STDC__} is normally 0, but is 1 if the user specifies strict
1233c87b03e5Sespieconformance to the C Standard.  GCC follows the host convention when
1234c87b03e5Sespieprocessing system include files, but when processing user files it follows
1235c87b03e5Sespiethe usual GNU C convention.
1236c87b03e5Sespie
1237c87b03e5Sespie@item
1238c87b03e5SespieUndefining @code{__STDC__} in C++.
1239c87b03e5Sespie
1240c87b03e5SespiePrograms written to compile with C++-to-C translators get the
1241c87b03e5Sespievalue of @code{__STDC__} that goes with the C compiler that is
1242c87b03e5Sespiesubsequently used.  These programs must test @code{__STDC__}
1243c87b03e5Sespieto determine what kind of C preprocessor that compiler uses:
1244c87b03e5Sespiewhether they should concatenate tokens in the ISO C fashion
1245c87b03e5Sespieor in the traditional fashion.
1246c87b03e5Sespie
1247c87b03e5SespieThese programs work properly with GNU C++ if @code{__STDC__} is defined.
1248c87b03e5SespieThey would not work otherwise.
1249c87b03e5Sespie
1250c87b03e5SespieIn addition, many header files are written to provide prototypes in ISO
1251c87b03e5SespieC but not in traditional C@.  Many of these header files can work without
1252c87b03e5Sespiechange in C++ provided @code{__STDC__} is defined.  If @code{__STDC__}
1253c87b03e5Sespieis not defined, they will all fail, and will all need to be changed to
1254c87b03e5Sespietest explicitly for C++ as well.
1255c87b03e5Sespie
1256c87b03e5Sespie@item
1257c87b03e5SespieDeleting ``empty'' loops.
1258c87b03e5Sespie
1259c87b03e5SespieHistorically, GCC has not deleted ``empty'' loops under the
1260c87b03e5Sespieassumption that the most likely reason you would put one in a program is
1261c87b03e5Sespieto have a delay, so deleting them will not make real programs run any
1262c87b03e5Sespiefaster.
1263c87b03e5Sespie
1264c87b03e5SespieHowever, the rationale here is that optimization of a nonempty loop
1265c87b03e5Sespiecannot produce an empty one, which holds for C but is not always the
1266c87b03e5Sespiecase for C++.
1267c87b03e5Sespie
1268c87b03e5Sespie@opindex funroll-loops
1269c87b03e5SespieMoreover, with @option{-funroll-loops} small ``empty'' loops are already
1270c87b03e5Sespieremoved, so the current behavior is both sub-optimal and inconsistent
1271c87b03e5Sespieand will change in the future.
1272c87b03e5Sespie
1273c87b03e5Sespie@item
1274c87b03e5SespieMaking side effects happen in the same order as in some other compiler.
1275c87b03e5Sespie
1276c87b03e5Sespie@cindex side effects, order of evaluation
1277c87b03e5Sespie@cindex order of evaluation, side effects
1278c87b03e5SespieIt is never safe to depend on the order of evaluation of side effects.
1279c87b03e5SespieFor example, a function call like this may very well behave differently
1280c87b03e5Sespiefrom one compiler to another:
1281c87b03e5Sespie
1282c87b03e5Sespie@example
1283c87b03e5Sespievoid func (int, int);
1284c87b03e5Sespie
1285c87b03e5Sespieint i = 2;
1286c87b03e5Sespiefunc (i++, i++);
1287c87b03e5Sespie@end example
1288c87b03e5Sespie
1289c87b03e5SespieThere is no guarantee (in either the C or the C++ standard language
1290c87b03e5Sespiedefinitions) that the increments will be evaluated in any particular
1291c87b03e5Sespieorder.  Either increment might happen first.  @code{func} might get the
1292c87b03e5Sespiearguments @samp{2, 3}, or it might get @samp{3, 2}, or even @samp{2, 2}.
1293c87b03e5Sespie
1294c87b03e5Sespie@item
1295c87b03e5SespieNot allowing structures with volatile fields in registers.
1296c87b03e5Sespie
1297c87b03e5SespieStrictly speaking, there is no prohibition in the ISO C standard
1298c87b03e5Sespieagainst allowing structures with volatile fields in registers, but
1299c87b03e5Sespieit does not seem to make any sense and is probably not what you wanted
1300c87b03e5Sespieto do.  So the compiler will give an error message in this case.
1301c87b03e5Sespie
1302c87b03e5Sespie@item
1303c87b03e5SespieMaking certain warnings into errors by default.
1304c87b03e5Sespie
1305c87b03e5SespieSome ISO C testsuites report failure when the compiler does not produce
1306c87b03e5Sespiean error message for a certain program.
1307c87b03e5Sespie
1308c87b03e5Sespie@opindex pedantic-errors
1309c87b03e5SespieISO C requires a ``diagnostic'' message for certain kinds of invalid
1310c87b03e5Sespieprograms, but a warning is defined by GCC to count as a diagnostic.  If
1311c87b03e5SespieGCC produces a warning but not an error, that is correct ISO C support.
1312c87b03e5SespieIf test suites call this ``failure'', they should be run with the GCC
1313c87b03e5Sespieoption @option{-pedantic-errors}, which will turn these warnings into
1314c87b03e5Sespieerrors.
1315c87b03e5Sespie
1316c87b03e5Sespie@end itemize
1317c87b03e5Sespie
1318c87b03e5Sespie@node Warnings and Errors
1319c87b03e5Sespie@section Warning Messages and Error Messages
1320c87b03e5Sespie
1321c87b03e5Sespie@cindex error messages
1322c87b03e5Sespie@cindex warnings vs errors
1323c87b03e5Sespie@cindex messages, warning and error
1324c87b03e5SespieThe GNU compiler can produce two kinds of diagnostics: errors and
1325c87b03e5Sespiewarnings.  Each kind has a different purpose:
1326c87b03e5Sespie
1327c87b03e5Sespie@itemize @w{}
1328c87b03e5Sespie@item
1329c87b03e5Sespie@dfn{Errors} report problems that make it impossible to compile your
1330c87b03e5Sespieprogram.  GCC reports errors with the source file name and line
1331c87b03e5Sespienumber where the problem is apparent.
1332c87b03e5Sespie
1333c87b03e5Sespie@item
1334c87b03e5Sespie@dfn{Warnings} report other unusual conditions in your code that
1335c87b03e5Sespie@emph{may} indicate a problem, although compilation can (and does)
1336c87b03e5Sespieproceed.  Warning messages also report the source file name and line
1337c87b03e5Sespienumber, but include the text @samp{warning:} to distinguish them
1338c87b03e5Sespiefrom error messages.
1339c87b03e5Sespie@end itemize
1340c87b03e5Sespie
1341c87b03e5SespieWarnings may indicate danger points where you should check to make sure
1342c87b03e5Sespiethat your program really does what you intend; or the use of obsolete
1343c87b03e5Sespiefeatures; or the use of nonstandard features of GNU C or C++.  Many
1344c87b03e5Sespiewarnings are issued only if you ask for them, with one of the @option{-W}
1345c87b03e5Sespieoptions (for instance, @option{-Wall} requests a variety of useful
1346c87b03e5Sespiewarnings).
1347c87b03e5Sespie
1348c87b03e5Sespie@opindex pedantic
1349c87b03e5Sespie@opindex pedantic-errors
1350c87b03e5SespieGCC always tries to compile your program if possible; it never
1351c87b03e5Sespiegratuitously rejects a program whose meaning is clear merely because
1352c87b03e5Sespie(for instance) it fails to conform to a standard.  In some cases,
1353c87b03e5Sespiehowever, the C and C++ standards specify that certain extensions are
1354c87b03e5Sespieforbidden, and a diagnostic @emph{must} be issued by a conforming
1355c87b03e5Sespiecompiler.  The @option{-pedantic} option tells GCC to issue warnings in
1356c87b03e5Sespiesuch cases; @option{-pedantic-errors} says to make them errors instead.
1357c87b03e5SespieThis does not mean that @emph{all} non-ISO constructs get warnings
1358c87b03e5Sespieor errors.
1359c87b03e5Sespie
1360c87b03e5Sespie@xref{Warning Options,,Options to Request or Suppress Warnings}, for
1361c87b03e5Sespiemore detail on these and related command-line options.
1362