[LCP]Rounding questions

Greg Black gjb at gbch.net
Sun Sep 8 21:11:06 UTC 2002


"Mike & Penny" wrote:

| b) If a bug appears when optimization is turned on that does not necessarily
| mean it is a bug in the optimization process.

I was talking about bugs that appear when correct code is broken
by the optimiser.  This happens much more frequently than bugs
in code generation without attempts at optimisation.  And, in
the case I was discussing, we were dealing with code that was
presumed to be correct.  If the code was in fact buggy, then all
bets are off.

I will also repeat my earlier comment that it's more likely that
there are in fact bugs in the code than in the compiler and that
the symptoms that have been reported are extremely common signs
of buggy code.  I'm not suggesting that the first conclusion to
reach is that you have a buggy compiler.

| Incorrect code MAY still compile and execute correctly (as the
| programmer thinks it should) and a compiler is not supposed to be judged
| either better nor worse for how it behaves with incorrect code.
| 
| Sorry, I am too inexperienced doing serious debugging of C to be able to
| give you examples of this.

Here is the canonical example in C:

    int i = 5;

    i = ++i + 1;

If the programmer convinces himself that the correct value of i
after the above is executed is 7 and if his compiler in fact
produces that value, the programmer could well think that he has
got things right and that his compiler is right.

However, because the given assignment statement is explicitly
undefined in C, the compiler is entitled to set i to any value
it likes or to burn down your house.  The compiler is right, but
the programmer is wrong.

Greg




More information about the linuxCprogramming mailing list