Negating a short?

Andy Valencia dont at spam.me
Tue Nov 5 20:29:08 UTC 2024


On Tuesday, 5 November 2024 at 19:37:32 UTC, Dennis wrote:
> On Tuesday, 5 November 2024 at 17:32:00 UTC, Andy Valencia 
> wrote:
>> I ended up with this, but is negating a short really this 
>> problematic, or did I miss something?
>
> This is a relic from when integer promotion was added to unary 
> operators to match the behavior of C compilers. You can add the 
> `-preview=intpromote` flag to the compiler to make the 
> deprecation warnings go away for a simple `-x`, but that flag 
> is enabled by default since dmd version 2.099 / ldc version 
> 1.29, so simply updating your compiler should also fix it.

I still see:

tst15.d(6): Error: cannot implicitly convert expression 
`-cast(int)s` of type `int` to `short`


For:

     import std.stdio : writeln;

     void
     main() {
         short s = -5;
         s = -s;
         writeln(s);
     }

This is 1.40 beta4?



More information about the Digitalmars-d-learn mailing list