Can anyone explain this?
% cat t.c
#include <stdio.h>
#define FIRST "first"
#define SECOND "second"
int
main(int argc, char *argv[])
{
switch (argv[1][0]) {
case FIRST[0]:
case 'f':
printf("%s == FIRST\n", argv[1]);
break;
case SECOND[0]:
case 's':
printf("%s == SECOND\n", argv[1]);
break;
}
return 0;
}
% gcc -o t -W -Wall -g t.c
t.c: In function `main':
t.c:10: error: case label does not reduce to an integer constant
t.c:14: error: case label does not reduce to an integer constant
It certainly looks constant to me, and it should be promotable to an
integer exactly as the neighboring case label is. This is gcc 3.4.5 FWIW.
TIA,
RM
% cat t.c
#include <stdio.h>
#define FIRST "first"
#define SECOND "second"
int
main(int argc, char *argv[])
{
switch (argv[1][0]) {
case FIRST[0]:
case 'f':
printf("%s == FIRST\n", argv[1]);
break;
case SECOND[0]:
case 's':
printf("%s == SECOND\n", argv[1]);
break;
}
return 0;
}
% gcc -o t -W -Wall -g t.c
t.c: In function `main':
t.c:10: error: case label does not reduce to an integer constant
t.c:14: error: case label does not reduce to an integer constant
It certainly looks constant to me, and it should be promotable to an
integer exactly as the neighboring case label is. This is gcc 3.4.5 FWIW.
TIA,
RM
Comment