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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 23 03:22:49 PDT 2012


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


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug at yahoo.com.au
         Resolution|                            |INVALID


--- Comment #6 from Don <clugdbug at yahoo.com.au> 2012-04-23 03:23:44 PDT ---
(In reply to comment #0)
> In DMD 2.059beta this code compiles with no warnings or errors:
> void main(string[] args) {
>     uint x;
>     ubyte y = cast(ubyte)args.length;
>     ubyte z = x % y;
> }

> So I'd like code similar to this too to compile with no need of a cast:
> void main() {
>     ulong x;
>     int y;
>     int z = x % y;
> }

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.

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

-- 
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