R
Richard Herring
Hendrik Schober said:James said:Exactly. And if the language defines a type T such that T - T
-> T, then that type isn't an abstraction of the natural
numbers. For a type to be usable as an abstraction of the
natural numbers, the results of subtraction must be another
type, or subtraction must not be supported. (Modula-2, for
example, takes that latter course.) C++ doesn't have such a
type; the closest we can come is int.
Mhmm. You got me thinking here.
[...]
In the end, a language is designed the way it is designed. You
can fight it, but you won't win. Kernighan and Richie decided
that the principal integral type in C would be int; all other
types have been added for specific needs, but int remains THE
integral type. Anytime you use anything else (for integral
values, of course), you're fighting the language: introducing
additional complexity and additional possibilities for errors.Mhmm. Then who added 'size_t' to be used for sizes
to this language?I don't know. That came a lot later. (Don't forget, however,
that size_t was originally designed to represent something very
low level, which often wouldn't fit in an int.)I know. That's obviously an error in the conception of theIt is recycled throughout most of the C++ std lib (as
'size_type').
library, but it's too late to change it now, despite the
problems it causes.
I'm still not convinced, the choice of unsigned for counting
objects throughout the whole std lib is wrong.
[If you'll forgive a linguistic nitpick, that's ambiguous in English. I
take it you mean you're not convinced *that* the choice of unsigned is
wrong. ]
It's fine for *counting*. The problem is that it's used for several
other things as well. An index is not a count, though it can be mapped
to one. The difference of two indices is definitely not a count.