Treating the abusive unsigned syndrome
Sean Kelly
sean at invisibleduck.org
Wed Nov 26 16:46:37 PST 2008
Andrei Alexandrescu wrote:
> Sean Kelly wrote:
>> Don wrote:
>>>
>>> Although it would be nice to have a type which was range-limited,
>>> 'uint' doesn't do it. Instead, it guarantees the number is between 0
>>> and int.max*2+1 inclusive. Allowing mixed operations encourages
>>> programmers to focus the benefit of 'the lower bound is zero!' while
>>> forgetting that there is an enormous downside ('I'm saying that this
>>> could be larger than int.max!')
>>
>> This inspired me to think about where I use uint and I realized that I
>> don't. I use size_t for size/length representations (largely because
>> sizes can theoretically be >2GB on a 32-bit system), and ubyte for
>> bit-level stuff, but that's it.
>
> For the record, I use unsigned types wherever there's a non-negative
> number involved (e.g. a count). So I'd be helped by better unsigned
> operations.
To be fair, I generally use unsigned numbers for values that are
logically always positive. These just tend to be sizes and counts in my
code.
> I wonder how often these super-large arrays do occur on 32-bit systems.
> I do have programs that try to allocate as large a contiguous matrix as
> possible, but never sat down and tested whether a >2GB chunk was
> allocated on the Linux cluster I work on. I'm quite annoyed by this >2GB
> issue because it's a very practical and very rare issue in a weird
> contrast with a very principled issue (modeling natural numbers).
Yeah, I have no idea how common they are, though my guess would be that
they are rather uncommon. As a library programmer, I simply must assume
that they are in use, which is why I use size_t as a matter of course.
Sean
More information about the Digitalmars-d
mailing list