New integer promotion rules

Ali Çehreli acehreli at yahoo.com
Wed Jan 17 23:26:44 UTC 2018


On 01/17/2018 02:30 PM, rumbu wrote:

 > 1. Why do I need explicitely to promote my byte to int in order to
 > assign it to an ulong?
 > 2.077: ulong u = -b; 2.088: ulong u = -cast(int)b;

You're not assigning your byte to ulong; you're assigning the expression 
-b to ulong. -b is discovered to have unintended behavior, which is now 
fixed. We have to go throught a transition period not to break old code 
that may have depended on the old unintended behavior.

 > 2. Why do I need a cast(int) to assign a byte to an ubyte, since I'm
 > explicitely cast it?
 > 2.077: ubyte c = cast(ubyte)-b; 2.088: ubyte c = cast(ubyte)-cast(int)b

Same issue: the question is about what -b means before your cast in the 
2.077 version of the code.

Ali



More information about the Digitalmars-d-learn mailing list