disabling unary "-" for unsigned types

dsimcha dsimcha at yahoo.com
Sun Feb 14 14:15:43 PST 2010


== Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
> 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

Ok, but you could still do it just by using an explicit cast.  When you're
thinking of how things are represented at the bit level, this is basically type
punning.  It should be allowed in a systems language, but it should require an
explicit cast.  Using unary - to get the two's complement of a number is a way of
getting around they type system and is probably a bug more often than an
intentional idiom.



More information about the Digitalmars-d mailing list