[Issue 293] New: Expression uint.max + 1 yields 0 (zero)

Oskar Linde oskar.lindeREM at OVEgmail.com
Thu Aug 17 02:31:21 PDT 2006


d-bugmail at puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=293
> 
>            Summary: Expression uint.max + 1 yields 0 (zero)
>            Product: D
>            Version: 0.164
>           Platform: PC
>         OS/Version: Linux
>             Status: NEW
>           Severity: normal
>           Priority: P2
>          Component: DMD
>         AssignedTo: bugzilla at digitalmars.com
>         ReportedBy: m.faustino at gmail.com
> 
> 
> 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);
> 
> }
> //----------------------------------------------------------

This is not a bug. Look under Integer Promotions on 
http://www.digitalmars.com/d/type.html

type type of (uint) + (int) is (uint), not (ulong)

/Oskar



More information about the Digitalmars-d-bugs mailing list