Portability of uint over/underflow behavior
Don
nospam at nospam.com
Sat Jan 3 12:32:07 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,
Not so. You can rely on this. It's a fundamental mathematical property.
but is it universal enough that it can be considered portable in
> practice?
More information about the Digitalmars-d
mailing list