Integer overflow and underflow semantics

Era Scarecrow rtcvb32 at yahoo.com
Sat May 5 01:23:50 PDT 2012


On Saturday, 5 May 2012 at 07:10:28 UTC, Alex Rønne Petersen 
wrote:

> Right, but the question was whether the language guarantees 
> what I described. C and C++ don't, and IMO, we should strive to 
> fix that.

  I can't see why it wouldn't, unless the compiler adds in checks 
and changes it's behavior or the assembler does it's own quirky 
magic. The bit patterns of how they end up are pretty fixed, it's 
just how we interpret them.

  I know before when i needed to know if it overflowed and 
simulated the carry flag, i ended up using a larger type of int. 
(This was for a custom multiple precision unsigned ints)



  Of course now that I think about it, if anything ends up using 
MMX for it's registers, the rules do change a little. MMX don't 
overflow if I remember right, they just cap/truncate to the 
Max/Min. Since it's intended more for multimedia... If the 
compiler uses those, I can't tell you what would happen.


More information about the Digitalmars-d mailing list