C
CBFalconer
Dan said:.... snip ...
Signed integers and unsigned integers are fairly different beasts,
intended for different purposes. Avoid unsigned integers unless
you need their special semantics (or the additional range), even
if you're only manipulating positive values. After all, the
prototype of main() isn't
int main(unsigned argc, char **argv);
despite the fact that argc is not supposed to have negative values.
If it's intended for usual arithmetic operations, use signed
integer. If it's intended for bit manipulation operations and/or
modulo arithmetic, use unsigned integer.
Avoid as much as possible mixing the two flavours in the same
expression, because very nasty bugs may arise.
The fact that size_t is unsigned is a real pain in the ass, because
this type is seldom used in a genuine unsigned context. It should
have been signed, for the same reason that argc is signed.
There are two fundamental problems without compatible resolution.
First, int to unsigned conversion is always possible, while the
reverse may not be. This encourages the use of ints. Secondly,
size_t usually represents things that can be addressed in the
system, and this is very unlikely to waste any bit positions.
This more or less mandates the use of size_t (and thus unsigned)
in many places.