ushort + ushort = int?

Andrey saasecondbox at yandex.ru
Mon Aug 20 08:34:56 UTC 2018


Hello,
Here is a code that you can execute using online compiler 
https://run.dlang.io/:

>import std.stdio;
>void main()
>{
>    ushort first = 5;
>    ushort second = 1000;
> 
>    ushort result = first + second;
> 
>    writeln(result);
>}

I hae this error:
> onlineapp.d(7): Error: cannot implicitly convert expression 
> cast(int)first + cast(int)second of type int to ushort

Why they are "int" when I declared them as "ushort"???
ushort + ushort = ushort, not int.

In C++ there aren't any such issues...


More information about the Digitalmars-d-learn mailing list