Malcolm said:
Not all integers count things in memory. In this case a perfectly reasonable
strategy would be to number the errors consecutively and use the number to
index into an array of messages, but in fact the C standard hasn't imposed
that.
Ok.
Now suppose I have:
static const char *rank_names[] = { NULL, "Ace", "Deuce", "Three", "Four",
"Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
struct card { enum rank rank; enum suit suit; };
Does the mere fact that I'm going to sooner or later write
rank_names[mycard.rank] mean that you'd consider the rank field in that
struct "something used to count things in memory"?
Would you be no more surprised to see that field declared as a size_t than
you are usually for other uses of that type? Do you include it in the
count when you say that "most integers are used to index arrays",
regardless of the fact that that field is going to be used for other
purposes too, having nothing to do with the memory of a computer, and that
I could simply replace that array with a switch statement with no
difference in semantics?
At the top of main in the last nontrivial program I've written, I declared
an int to temporarily hold the value of errno when I must preserve it
through library calls, an int used for a status (EXIT_SUCCESS or
EXIT_FAILURE), and a int to contain a number of digit to be passed in a
printf("%*lu", ...) call. Then I declared an array of BUFSIZ unsigned
chars to hold data to be written to/read from a binary file, two time_t's
(which happen to be long int on my system), an unsigned int to hold a seed
to call srand with, and a few size_t's used for sizes of things. The only
times I use the [] operator is with the argv array.