Kagamin wrote:
bearophile Wrote:

In my programs I use use unsigned integers and unsigned longs as: -
bitfields, a single size_t, for example to represent a small set of
items. - bitarrays, in an array of size_t, to represent a larger
set, to have array of bit flags, etc. - to pack small variables
into a uint, size_t, etc, for example use the first 5 bits to
represent a, the following 2 bits to represent b, etc. In such
situation I have never pack such variables into a signed int.

I think, signed ints can hold bits as gracefully as unsigned ones.

Problem is there is an odd jump whenever the sign bit gets into play. An expert programmer can easily deal with that, but it's rather tricky.

- when I need very large integer values, but this has to be done
with care, because they can't be converted back to ints.

I don't think that large integers know or respect computers-specific
integers limits. They just get larger and larger.

Often large integers hold counts or sizes of objects fitting in computer memory. There is a sense of completeness of a systems-level language in being able to use a native type to express any offset in memory. That's why it would be some of a bummer if we defined size_t as int on 32-bit systems: I, at least, would feel like giving something up.


Andrei

Reply via email to