[Issue 11493] New: dlang.org/type.html incorrectly says that you can't cast from -1 to unsigned types
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Nov 10 13:22:59 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11493
Summary: dlang.org/type.html incorrectly says that you can't
cast from -1 to unsigned types
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: websites
AssignedTo: nobody at puremagic.com
ReportedBy: jmdavisProg at gmx.com
--- Comment #0 from Jonathan M Davis <jmdavisProg at gmx.com> 2013-11-10 13:22:54 PST ---
dlang.org/type.html gives this example
ubyte u1 = cast(byte)-1; // error, -1 cannot be represented in a ubyte
ushort u2 = cast(short)-1; // error, -1 cannot be represented in a ushort
uint u3 = cast(int)-1; // ok, -1 can be represented in a uint
ulong u4 = cast(long)-1; // ok, -1 can be represented in a ulong
However, all 4 compile, which makes sense, because casts are blunt and don't
care about what does and doesn't fit. This won't compile
ubyte u1 = -1;
ushort u2 = -1;
which is a bit interesting given that this compiles just fine
byte i1 = -1;
short i2 = -1;
ubyte u1 = i1;
ushort u2 = i2;
But regardless of whether
ubyte u1 = -1;
ushort u2 = -1;
should compile, the example in documentation definitely should, and the
documentation claims that it shouldn't, so the documentation is wrong and needs
to be updated.
And honestly, I don't understand the logic of how -1 can be represented in a
uint but not a ushort like the docs claim, since it can't be represented in
either, since they're unsigned, so I don't understand how the example in the
docs ever would have made sense.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list