www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Language Reference: Usual Arithmetic Conversions

reply Morlan <home valentimex.com> writes:
The following section from the Language Reference does not correspond to
the current dmd compiler (v2.052, Windows) behaviour:

"
Integer values cannot be implicitly converted to another type that cannot
represent the integer bit pattern after integral promotion. For 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(ulong)-1;  // ok, -1 can be represented in a ulong
"

Both byte and short casts work all right.
Apr 05 2011
parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
On Tue, 05 Apr 2011 20:10:19 +0200, Morlan <home valentimex.com> wrote:

 The following section from the Language Reference does not correspond to
 the current dmd compiler (v2.052, Windows) behaviour:

 "
 Integer values cannot be implicitly converted to another type that cannot
 represent the integer bit pattern after integral promotion. For 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(ulong)-1;  // ok, -1 can be represented in a ulong
 "

 Both byte and short casts work all right.
Please use bugzilla to file issues: http://d.puremagic.com/issues/enter_bug.cgi -- Simen
Apr 05 2011