bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GCC optimizes integer overflow: bug or feature?


From: Robert Dewar
Subject: Re: GCC optimizes integer overflow: bug or feature?
Date: Tue, 19 Dec 2006 21:11:53 -0500
User-agent: Thunderbird 1.5.0.8 (Windows/20061025)

Denis Vlasenko wrote:

I want sane compiler. One in which N-bit integer variables stay exactly N-bit.
Without "magic" N+1 bit which is there "somethimes". a*2/2:
If I say "multiply by 2 and _after that_ divide by 2,
I meant that. Compiler can optimize it any way it wants,
as long as result is the same as unoptimized one.

I am sure others will say this too, but the demand that optimization
not affect behavior is entirely unrealistic and unreasonable. The
whole point of making things undefined in C is to allow compilers
the freedom to optimize. Now that does not mean that one should
always take advantage (my position is that you want to be careful
in taking advantage of undefined and make sure the gain is worth
the surprise), but to say that you should NEVER take advantage
of this would have terrible effects on the code.

Above: v is a signed entity. I expect (v < 0) to be equal to
"most significant bit is set". It's not about standards.
It's about sanity.

Well for sure I don't think you want minus zero to be less than
plus zero on a 1's complement machine, that would not be sane.
Things are never simple!
--
vda





reply via email to

[Prev in Thread] Current Thread [Next in Thread]