Re: case label does not reduce to an integer constant
- From: "Bartc" <bc@xxxxxxxxxx>
- Date: Sat, 12 Apr 2008 16:51:57 GMT
"Rex Mottram" <rexm@xxxxxxxx> wrote in message
news:5JmdnaLkgpQwPJ3VnZ2dnUVZ_uKpnZ2d@xxxxxxxxxxxxxx
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.
Possibly not allowed for the same reason that:
int x[FIRST[0]];
is not allowed, when declared outside a function (inside a function, it
might work as a VLA, but it is still not considered a constant).
I suppose there is a limit to what a compiler can do to determine an
expression is constant, or maybe it considers that the string "first" could
change (I managed to do this on lccwin, but gcc generated a crash when
attempting to change the constant string).
--
Bart
.
- References:
- case label does not reduce to an integer constant
- From: Rex Mottram
- case label does not reduce to an integer constant
- Prev by Date: Re: How to generate random numbers in C
- Next by Date: Re: Variable declaration followed by colon?
- Previous by thread: Re: case label does not reduce to an integer constant
- Next by thread: Completely Free online dating service, Completely free personals ...
- Index(es):
Relevant Pages
|