1

I've often wondered about the rationale behind the warning: array subscript is of type 'char' warning. I know I can cast it to an int or turn the warning off with -Wno-char-subscripts, but why is this considered an issue worth warning about? Does it have to do with the small of range of char? Or something else I'm not thinking of?

#include <stdio.h>
int main(void) {
        char a[10], i = 0;
        a[i] = 0; // i is a char, hence the warning.
        return 0;
}

Thanks for enlightening me.

Charlie Burns
  • 6,994
  • 20
  • 29

0 Answers0