Kagamin wrote:
Some people used to use unsigned integers as 'mere' non-negative numbers, but they're actually not numbers from range, they're numbers from entirely different algebra. And - yes - this causes subtle bugs.
Amen!
I actually think it's worse in D, because 'uint' is so easy to type,
it's far more seductive than 'unsigned int'.
Recent introduction of integer range promotions works hard in hiding
those bugs, so they manifest only in very rare corner cases.
It's not complete. It doesn't apply to arithmetic operations yet. Once
that's in place, D could become really harsh about mixing signed and
unsigned: if there's any chance the highest bit is set in the signed
type, mixing signed and unsigned should be illegal.
Ever wondered wheter a-=b and a+=-b equivalent? In most cases they are, except
for one. Do you remember? uint is not propagated to long. I've hit it recently.
It's exactly because unsigneds are not just non-negative numbers. So it's pain
to see their wide use as numbers for which sign-sensitive arithmetic operations
are meaningful.