On 10/31/2013 08:02 AM, David Brown wrote: > 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
They do: for (int i = 0; i < 5; i ++) a(p + i * 10); -> for (int p1 = p; p1 < p + 50; p1 += 10) a(p1); Andrew.