Portability of uint over/underflow behavior

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Jan 3 13:42:19 PST 2009


dsimcha wrote:
> 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?

Walter's intent is to put that guarantee in the language.

Andrei



More information about the Digitalmars-d mailing list