Operator implicit conversion difference
BBaz via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Nov 6 16:56:07 PST 2015
On Thursday, 5 November 2015 at 13:20:26 UTC, ixid wrote:
> This may have been overlooked in my other thread so I wanted to
> ask again:
>
> This seems very inconsistent, does a += b not lower to a = a +
> b? I guess not based on the below:
>
> ushort a = ushort.max, b = ushort.max;
>
>
> a += b; // Compiles fine
> a = a + b; // Error: cannot implicitly convert expression
> (cast(int)a + cast(int)b) of type int to ushort
What's inconsistent is the integral promotion of the add
expression result that stops from 4 bytes int:
---
int a, b;
a += b;
a = a + b;
---
is compiled but according to the specs, a + b result should be
widened to long:
http://dlang.org/expression.html#AddExpression
(ubyte, byte) until (uint int) should be widened and (long ,
ulong) wrapped. This behavior would match the specs better.
More information about the Digitalmars-d-learn
mailing list