'int' is enough for 'length' to migrate code from x86 to x64
bearophile via Digitalmars-d
digitalmars-d at puremagic.com
Wed Nov 19 08:12:36 PST 2014
David Gileadi:
> writefln("%s", b.length - a.length); // Yup, 2
> writefln("%s", a.length - b.length); // WAT?
> 18446744073709551614
Nowadays a better way to write such kind of code is using the
Phobos "signed" function:
writefln("%s", b.length.signed - a.length.signed);
writefln("%s", a.length.signed - b.length.signed);
> This is why I agree with Don that:
>
> > Having arr.length return an unsigned type, is a dreadful
> language mistake.
This mistake is by design. Walter has resisted several times
turning them into signed values, and even making size_t a type
strongly different from uint/ulong. I don't agree with this
design decision, but it's unlikely that Walter has changed his
mind on it. So better to go on and discuss other things more
likely to happen.
Bye,
bearophile
More information about the Digitalmars-d
mailing list