Prefer Signed or Unsigned in D?

John Carter via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Sep 2 14:22:57 PDT 2015


On Wednesday, 2 September 2015 at 11:03:00 UTC, ponce wrote:
> On Tuesday, 1 September 2015 at 23:06:50 UTC, John Carter wrote:
>> C/C++ discussion here....
>>
>>    http://blog.robertelder.org/signed-or-unsigned-part-2/
>>
>> D rules here...
>>
>>    http://dlang.org/type.html#integer-promotions
>
> Everything Bjarne said still applies equally to D code, since 
> integer promotion is identical with C from what I understand.

Hmm. What Robert Elder says also applies still. And in my world 
his argument about undefined behavior carries weight.

Bugs that emerge from different optimizations / different 
versions of the compiler / on different CPU's are nightmares in 
my domain.

Here is a bug that existed in the JDK for 9 years (and probably 
in many other places....)
http://googleresearch.blogspot.co.nz/2006/06/extra-extra-read-all-about-it-nearly.html

So given the advice on mixing unsigned and signed, and the 
complexity of Dominikus's code to get signed and unsigned code to 
compare sanely....

Maybe if his code becomes standard in D...

Yup, mixing signed and unsigned is A Bad Thing, and you best go 
with whatever your base libraries give you.

The whole problem....
    http://www.di.unipi.it/~ruggieri/Papers/semisum.pdf
...makes me feel vaguely ill and long for a Numerical Tower.

I really must get around to benchmarking BigInt....





More information about the Digitalmars-d-learn mailing list