1

I get the following warning from gcc:

labs.c:760:2: error: array subscript has type ‘char’ [-Werror=char-subscripts]
  wrbuf[cmdlen++]=(unsigned char)(basictoken[from]>>8);
  ^
cc1: all warnings being treated as errors

Debugging with gdb it reports both side of similar type:

760 wrbuf[cmdlen++]=(unsigned char)(token[from]>>8);
(gdb) whatis wrbuf[cmdlen]
type = unsigned char
(gdb) whatis (unsigned char)(token[from]>>8)
type = unsigned char

Why is this warning? It disturbs me because if I want to make available format for ctypes the warning is turned to error.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user2469202
  • 338
  • 3
  • 9

1 Answers1

3
error: array subscript has type ‘char'

It's telling you about the array subscript, cmdlen or from.

How is cmdlen and from defined? Is one of them a char? I suspect so...

Charlie Burns
  • 6,994
  • 20
  • 29
  • cmdle is char, from is int – user2469202 Nov 11 '13 at 02:00
  • well, changing cmdlen to int solves the question. However I'm a bit surprised why is mandatory to use an integer for a few bytes long array. :( Anyway, thanks for the help. – user2469202 Nov 11 '13 at 02:13
  • 1
    Yes, I agree. Asking StackOverflow for the rational behind that would be a good question. Perhaps it's because in some instances the compiler doesn't know the size of the array and using a char as an index is questionable because of it's range. But, I don't know... – Charlie Burns Nov 11 '13 at 02:17
  • Let's see what they say... http://stackoverflow.com/questions/19897968/rationale-behind-warning-array-subscript-is-of-type-char – Charlie Burns Nov 11 '13 at 02:34