'int' is enough for 'length' to migrate code from x86 to x64
bearophile via Digitalmars-d
digitalmars-d at puremagic.com
Wed Nov 19 09:41:19 PST 2014
ketmar:
> ah, let range checking catch that.
No thanks, I prefer to not have bugs in the first place.
> besides, overflows are possible with signed ints too,
From my experience in coding in D they are far more unlikely than
sign-related bugs of array lengths.
> so what signed length does is simply hiding the bad code.
Signed lengths avoids traps that are quite easy to fall into.
> any code reviewer must ring
> a bell when he sees length subtraction without prior checking,
> be it signed or unsigned.
The unsigned nature of array lengths is more tricky than that.
They cause troubles even if you just compare (with <) a length
with a signed value.
Bye,
bearophile
More information about the Digitalmars-d
mailing list