Treating the abusive unsigned syndrome

Nick Sabalausky a at a.a
Wed Nov 26 12:44:45 PST 2008


"Michel Fortin" <michel.fortin at michelf.com> wrote in message 
news:ggjpn4$1v0m$1 at digitalmars.com...
> On 2008-11-25 10:59:01 -0500, Andrei Alexandrescu 
> <SeeWebsiteForEmail at erdani.org> said:
>
>> (3) u - u
>
> Just a note here, because it seems to me you're confusing two issues with 
> that "u - u" thing. The problem with "u - u" isn't one of unsigned vs. 
> signed integers at all. It's a problem of possibly going out of range, a 
> problem that can happen with any type but is more likely with unsigned 
> integers since they're often near zero.
>
> If you want to attack that problem, I think it should be done in a 
> coherent manner with other out-of-range issues. Going below uint.min for 
> an uint or below int.min for an int should be handled the same way. 
> Personally, I'd just add a compiler switch for runtime range checking 
> (just as for array bound checking).
>

I'd love to see D get the ability to turn on/off runtime range checking, but 
doing nothing more than a program-wide (or module-wide if compiling 
one-at-a-time) compiler switch is way too large-grained and blunt. I would 
want to also see C#'s:

checked(expr)
unchecked(expr)
checked { code }
unchecked { code }

> Treating the result u - u as __intuint is dangerous: uint.max - 1U gives 
> you a value which int cannot hold, but you'd allow it to convert 
> implicitly and without warning to int? I don't like it.
>
> -- 
> Michel Fortin
> michel.fortin at michelf.com
> http://michelf.com/
> 





More information about the Digitalmars-d mailing list