"Unsigned-related bugs never occur in real code."

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Jan 21 10:51:35 PST 2010


Rainer Deyke wrote:
> Don wrote:
>> bearophile wrote:
>>> And abs() of an unsigned number probably needs a compilation warning.
>> Not a warning, it's always an error.
> 
> I can imagine abs(x) being useful in a generic function where x can be
> either signed or unsigned.

std.traits has a Unsigned template. I plan to add two functions: 
signed(x) and unsigned(x), which transform the integral x into the 
signed/unsigned integral of the same size. Generic code could then call 
signed or unsigned wherever necessary. For abs, they'd have to call 
abs(signed(expr)) which I believe clarifies intent and averts bugs like 
mine.

Alas, that's not fixing everything...


Andrei



More information about the Digitalmars-d mailing list