Matthew Woehlke writes:
(WCTS) ...an explicit typecast to int doesn't solve this? Seems to work
here:
$ gcc -Wall -Wextra -o aci arrayci.c
arrayci.c: In function `main':
arrayci.c:7: warning: array subscript has type `char'
$ gcc -Wall -Wextra -DCAST='(int)(unsigned)' -o aci arrayci.c
$ cat arrayci.c
#ifndef CAST
#define CAST
#endif
int main() {
char c = 'q';
char foo[256] = { 0 };
return foo[CAST c];
}
That's buggy. char can be signed, so promoting char to int,
whether or not by an explicit cast to int, means that you may
be derefencing negative indices into the array. The correct
fix is to cast to unsigned char (or, in the m4 source code, use
the to_uchar inline function, which has better type safety).