The expression uint.max + 1, yields 0 (zero). For example, the following code will print "4294967296 == 0":
//----------------------------------------------------------
import std.stdio;
void main()
{
ulong u = uint.max;
writefln(u + 1, " == ", uint.max + 1);
}
//----------------------------------------------------------
Comment #1 by bugzilla — 2006-08-17T13:25:03Z
That's how fixed precision integer arithmetic works when it overflows. Not a bug.
Comment #2 by m.faustino — 2006-08-17T13:41:07Z
(In reply to comment #1)
> That's how fixed precision integer arithmetic works when it overflows. Not a
> bug.
>
So why (u + 1) doesn't overflow when (uint.max + 1) does?
In the code I wrote, aren't those two expressions semantically equivalent?
Comment #3 by bugzilla — 2006-08-17T13:56:13Z
u+1 adds 1 to a ulong, which does not overflow because it's a 64 bit type which is large enough to represent 4294967296. uint.max+1 is a uint, which does overflow because it's a 32 bit type and not large enough to hold 4294967296.
The expressions are not semantically equivalent.
Comment #4 by m.faustino — 2006-08-17T14:09:36Z
Ok, thanks. Sorry for the false bug report though.