Chapter 11. Known Causes of Trouble with GCC
Undefining
•
__STDC__
Programs written to compile with C++-to-C translators get the value of
the C compiler that is subsequently used. These programs must test
kind of C preprocessor that compiler uses: whether they should concatenate tokens in the ISO C
fashion or in the traditional fashion.
These programs work properly with GNU C++ if
otherwise.
In addition, many header files are written to provide prototypes in ISO C but not in traditional
C. Many of these header files can work without change in C++ provided
is not defined, they will all fail, and will all need to be changed to test explicitly for C++
__STDC__
as well.
Deleting "empty" loops.
•
Historically, GCC has not deleted "empty" loops under the assumption that the most likely reason
you would put one in a program is to have a delay, so deleting them will not make real programs
run any faster.
However, the rationale here is that optimization of a nonempty loop cannot produce an empty one,
which holds for C but is not always the case for C++.
Moreover, with
-funroll-loops
ior is both sub-optimal and inconsistent and will change in the future.
Making side effects happen in the same order as in some other compiler.
•
It is never safe to depend on the order of evaluation of side effects. For example, a function call like
this may very well behave differently from one compiler to another:
void func (int, int);
int i = 2;
func (i++, i++);
There is no guarantee (in either the C or the C++ standard language definitions) that the increments
will be evaluated in any particular order. Either increment might happen first.
arguments
, or it might get
2, 3
Not allowing structures with volatile fields in registers.
•
Strictly speaking, there is no prohibition in the ISO C standard against allowing structures with
volatile fields in registers, but it does not seem to make any sense and is probably not what you
wanted to do. So the compiler will give an error message in this case.
Making certain warnings into errors by default.
•
Some ISO C testsuites report failure when the compiler does not produce an error message for a
certain program.
ISO C requires a "diagnostic" message for certain kinds of invalid programs, but a warning is
defined by GCC to count as a diagnostic. If GCC produces a warning but not an error, that is
correct ISO C support. If test suites call this "failure", they should be run with the GCC option
-pedantic-errors
11.12. Warning Messages and Error Messages
The GNU compiler can produce two kinds of diagnostics: errors and warnings. Each kind has a dif-
ferent purpose:
• Errors report problems that make it impossible to compile your program. GCC reports errors with
the source file name and line number where the problem is apparent.
in C++.
small "empty" loops are already removed, so the current behav-
, or even
3, 2
, which will turn these warnings into errors.
is defined. They would not work
__STDC__
.
2, 2
that goes with
__STDC__
to determine what
__STDC__
is defined. If
__STDC__
might get the
func
251
Need help?
Do you have a question about the ENTERPRISE LINUX 3 - USING GCC and is the answer not in the manual?
Questions and answers