On 30/10/13 16:56, Andrew Haley wrote:
> On 10/30/2013 03:23 PM, David Brown wrote:
>> I believe that's only a minor reason for making signed overflows
>> undefined behaviour.  If it were a matter of implementation, I think it
>> would have been made "implementation defined" rather than "undefined",
>> so that two's complement machines could use wrapping while other systems
>> (which are very rare now) could have other defined overflow behaviour.
>>
>> The main reason (again, this is my guess - I don't know what the C
>> standards folk /actually/ thought) is that there is no obvious "correct"
>> behaviour for signed overflow
> 
> A more important reason that having signed overflow undefined allows
> a lot of powerful loop optimization algorithms.
> 

Didn't I mention that?  I certainly meant to!

There was a recent discussion on comp.lang.c about this.  I don't know
how one could (or should) grade the relative importance of reasons, but
certainly by having signed overflow as undefined you can enable many
nice optimisations.  These don't really turn up in "normal" code - how
many people would explicitly write "if (i + 10 > i) ..."?  But with
inlining, templates, constant propagation, etc., this sort of code gets
generated - and it is very nice that the compiler can optimise it.

mvh.,

David


Reply via email to