Is this a bug?
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Apr 29 05:14:23 PDT 2014
On Tue, 29 Apr 2014 03:43:54 -0400, Andrey <none at none.no> wrote:
> btw,
>
> short a,b,c;
>
> a = b + c; //error: cannot implicitly convert expression of type 'int'
> to 'short'
>
> Guys!! Tell me that I have an old slutty version of the compiler...
No. It's due to integer promotion. All operations are done at the int
level, so the expression b + c is actually an int. C allows this
transgression because it's convenient. D makes you acknowledge that you
are throwing away bits the compiler generated for you.
Note, += does work:
a = b;
a += c;
-Steve
More information about the Digitalmars-d-learn
mailing list