Apparently unsigned types really are necessary

Mail Mantis mail.mantis.88 at gmail.com
Sun Jan 22 05:33:42 PST 2012


2012/1/22 Jonathan M Davis <jmdavisProg at gmx.com>:
> Another potentially nasty situation is subtraction. It
> can do fun things when you subtract one unsigned type from another if you're
> not careful...

It is unrelated to unsigned types in any way, isn't it?:

int a = 2_000_000_000;
assert( a + a == 4_000_000_000 ); // fail
assert( a + a == -294_967_296 );   // OK

Overflow bug is often related to casting negative value to unsigned
types, yes, but without these types we still may have unexpected
behaviour due to this bug, so this is barely a proper solution.


More information about the Digitalmars-d mailing list