What is this behavior and how do I disable or get around it?

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Sep 4 18:49:02 PDT 2016


On Monday, 5 September 2016 at 00:26:01 UTC, pineapple wrote:
> This program does not compile.
>
> Error: cannot implicitly convert expression (cast(int)x - 
> cast(int)x) of type int to ubyte
>
>     void main(){
>         ubyte x;
>         x = x - x;
>     }
>
> I don't even know what to say. Who thought this behavior was a 
> good idea?

See the sections 'Integer Promotions' and 'Usual Arithmetic 
Conversions' in the docs at [1].

[1] http://dlang.org/spec/type.html#integer-promotions



More information about the Digitalmars-d-learn mailing list