Treating the abusive unsigned syndrome
Michel Fortin
michel.fortin at michelf.com
Wed Nov 26 07:24:19 PST 2008
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).
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