Portability of uint over/underflow behavior

bearophile bearophileHUGS at lycos.com
Wed Jan 7 13:33:00 PST 2009


Don:
> What you're calling 'overflow' in unsigned operations is actually the 
> carry flag. The CPU also an overflow flag which applies to signed 
> operations.

I may need to work with numbers that are always >= 0 that can't fit in 63 bits. This has actually happened to me once.

A third possible syntax, even more localized (to be used with or instead of the other two possible syntaxes):

unsafe uint x = uint.max;
uint y = uint.max;
x++; // ==> OK, now x == 0
y++; // ==> throws runtime overflow exception

Bye,
bearophile



More information about the Digitalmars-d mailing list