Signed integer overflow undefined behavior or not?

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 13 01:37:39 PST 2015


On Friday, 13 November 2015 at 09:33:51 UTC, John Colvin wrote:
> I don't understand what you think is so complicated about it?
>

It is not that it is complicated, but that signed wraparound is 
almost always a bug. In C/C++, that result in very questionable 
optimizations. But defining the thing as wraparound is also 
preventing it to become an error. On the other hand, detection 
the overflow is expensive on most machines.

I think Don has a point and the spec should say something like :
signed integer overflow is defined as being a runtime error. For 
performance reasons, the compiler may choose to not emit error 
checking code and use wraparound semantic instead.

Or something along these lines.


More information about the Digitalmars-d mailing list