Portability of uint over/underflow behavior

dsimcha dsimcha at yahoo.com
Sat Jan 3 11:56:38 PST 2009


Is it portable to rely on unsigned integer types wrapping to their max value
when they are subtracted from too many times, i.e.

uint foo = 0;
foo--;
assert(foo == uint.max);

ulong bar = 0;
bar--;
assert(bar == ulong.max);

ubyte baz = 0;
baz--;
assert(baz == ubyte.max);

I assume that in theory this is hardware-specific behavior and not guaranteed
by the spec, but is it universal enough that it can be considered portable in
practice?



More information about the Digitalmars-d mailing list