N
Noob
[ NOTE : cross-posted to comp.lang.c and comp.unix.programmer,
please trim as you see fit ]
Hello,
My compiler (gcc 4.7) is being a little fussy about the following code:
(trimmed to a minimum)
#include <ctype.h>
int foo(const char *ext)
{
int ext_NNN = isdigit(ext[1]) && isdigit(ext[2]) && isdigit(ext[3]);
return ext_NNN;
}
$ gcc -Wall -c tutu.c
tutu.c: In function 'foo':
tutu.c:4:3: warning: array subscript has type 'char' [-Wchar-subscripts]
tutu.c:4:3: warning: array subscript has type 'char' [-Wchar-subscripts]
tutu.c:4:3: warning: array subscript has type 'char' [-Wchar-subscripts]
On this platform, isdigit seems to be a (complex) macro, and the preprocessor
digests my function into...
int foo(const char *ext)
{
int ext_NNN = (((__ctype_ptr__+sizeof(""[ext[1]]))[(int)(ext[1])])&04) && (((__ctype_ptr__+sizeof(""[ext[2]]))[(int)(ext[2])])&04) && (((__ctype_ptr__+sizeof(""[ext[3]]))[(int)(ext[3])])&04);
return ext_NNN;
}
Sweet baby Jesus... IOCCC winner here.
If I want to make the warnings disappear, I see two obvious work-arounds:
1) Set -Wno-char-subscripts
2) Cast isdigit's parameter to int (or to unsigned or to unsigned char)
3) Something else?
My questions :
- Is something wrong with my code, or is this just a QoI issue?
- How would you silence the warnings?
Regards.
please trim as you see fit ]
Hello,
My compiler (gcc 4.7) is being a little fussy about the following code:
(trimmed to a minimum)
#include <ctype.h>
int foo(const char *ext)
{
int ext_NNN = isdigit(ext[1]) && isdigit(ext[2]) && isdigit(ext[3]);
return ext_NNN;
}
$ gcc -Wall -c tutu.c
tutu.c: In function 'foo':
tutu.c:4:3: warning: array subscript has type 'char' [-Wchar-subscripts]
tutu.c:4:3: warning: array subscript has type 'char' [-Wchar-subscripts]
tutu.c:4:3: warning: array subscript has type 'char' [-Wchar-subscripts]
On this platform, isdigit seems to be a (complex) macro, and the preprocessor
digests my function into...
int foo(const char *ext)
{
int ext_NNN = (((__ctype_ptr__+sizeof(""[ext[1]]))[(int)(ext[1])])&04) && (((__ctype_ptr__+sizeof(""[ext[2]]))[(int)(ext[2])])&04) && (((__ctype_ptr__+sizeof(""[ext[3]]))[(int)(ext[3])])&04);
return ext_NNN;
}
Sweet baby Jesus... IOCCC winner here.
If I want to make the warnings disappear, I see two obvious work-arounds:
1) Set -Wno-char-subscripts
2) Cast isdigit's parameter to int (or to unsigned or to unsigned char)
3) Something else?
My questions :
- Is something wrong with my code, or is this just a QoI issue?
- How would you silence the warnings?
Regards.