What If I Don't Actually Like My Users?
Posted Apr 6, 2008 1:25 UTC (Sun) by
im14u2c (subscriber, #5246)
In reply to:
What If I Don't Actually Like My Users? by nix
Parent article:
What If I Don't Actually Like My Users?
I guess you could be even more pedantic and put 'U' suffixes on your array bounds too: int array[3U][5U]; ;-)
As for down-counting loops: The counter going negative is a red herring in terms of correct array accesses. What do the following two loops have in common?
for (i = 0; i < N; i++)
do_something(array[i]);
for (i = N-1; i >= 0; i--)
do_something(array[i]);
Answer? Both leave 'i' pointing one element past the end of the array. The only difference is which end.
I personally find negative array subscripting useful. The following is legitimate C code:
/* Take a histogram of signed 8-bit values */
int histogram[256];
int *hist_mid = histogram + 128;
signed char *data;
/* ... */
for (i = 0; i < N; i++)
hist_mid[data[i]]++;
And as far as the standard goes, at least this example from the C0x standard uses int to define array bounds (in the context of the new "Variable Length Array" feature being added to C).
*shrug*
You're right, though, it doesn't matter a whole lot. Just don't take my signed integer indices away, and I'll let you keep your unsigned ones. :-)
(
Log in to post comments)