On Thu, Dec 2, 2010 at 3:29 PM, Eric Smith <eric at brouhaha.com> wrote:
Ethan Dicks wrote:
...but I certainly wouldn't want that
statement optimized out entirely.
If the compiler optimized that out entirely, the compiler is defective.
?Optimizations are not supposed to change the semantics of well-formed code.
I agree. They are not. OTOH, IIRC, I had problems with the optimizer
on certain early versions of Lattice C on the Amiga where code ported
from, say, comp.sources.games, that worked as-is in a UNIX environment
(so no _horrible_ bugs), failed with optimization turned on, but ran
as expected with optimization turned off.
On the other hand, the compiler is free to optimize
? ?int i;
? ?for (i = 0; i < 100; i++)
? ? ? ?;
into
? ?int i;
? ?i = 100;
Since that does not change the semantics.
Agreed.
-ethan