Correct comparison of signed type with unsigned type (and vice versa)

Francesco Cattoglio francesco.cattoglio at gmail.com
Fri Feb 21 04:21:19 PST 2014


On Thursday, 20 February 2014 at 20:52:23 UTC, Xinok wrote:
> Others have suggested disallowing comparing a signed type with 
> an
> unsigned type. I think this is a better solution. Yes, it will
> add a small bit of overhead, but I believe it's more important
> for code to be correct than to be fast.
I totally agree. However, since we need correct code, we need way 
more features than this. I was surprised to find out that we 
don't have any "SafeInt" type in D... I was sure someone had made 
it but I wasn't able to find it anywhere.

My ideal int type:
-Has an equivalent of NaN, meaning it doesn't have "0 
initialization" which is somewhat bug-prone.
-Is able to signal errors like overflow/division by zero, would 
be nice if throwing could be avoided.
-Signed, but can be flagged as ">0 only", and signals an error if 
it gets assigned a negative value.
-Some extra features that are surely awesome but I'm forgetting 
right now.

> Any takers?
Man, I wish I had time :S


More information about the Digitalmars-d mailing list