disabling unary "-" for unsigned types

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Feb 14 14:02:12 PST 2010


dsimcha wrote:
> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
>> ulong x0;
>> static assert(!__traits(compiles, -x0));
>> uint x1;
>> static assert(!__traits(compiles, -x1));
>> ushort x2;
>> static assert(!__traits(compiles, -x2));
>> ubyte x3;
>> static assert(!__traits(compiles, -x3));
>> Sounds good?
>> Andrei
> 
> The more you bring up features to give the axe to, the more I find it funny that,
> not being a very good language lawyer, I wasn't aware that half of these features
> existed in the first place.  This is one of them.  Yes, definitely get rid of it.
>  It makes absolutely no sense.  If you want to treat your number like a signed
> int, then it should require an explicit cast.

I said the same. Walter's counter-argument is that 2's complement 
arithmetic is an inescapable reality that all coders must be aware of in 
D and its kin. Negation is really taking the two's complement of the 
thing. The fact that the type was unsigned is not of much import.

Andrei



More information about the Digitalmars-d mailing list