[Issue 7834] Assign x%int to int without cast

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 24 19:38:45 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7834



--- Comment #7 from bearophile_hugs at eml.cc 2012-04-24 19:39:48 PDT ---
(In reply to comment #6)

> These two bits of code aren't analogous.
> If y was -1, when cast to ulong it becomes 0xFFFF_FFFF_FFFF_FFFF
> Therefore, x % y could be 0.. ulong.max; there's no way that can fit into an
> int.
> The compiler is correct.

You are of course right, thank you Don and sorry SomeDude.


> OTOH if you change int -> uint, it works.


Right, this compiles:

void main() {
    ulong x;
    uint y = 1;
    int z = x % y;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list