Re: case label does not reduce to an integer constant




"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


.



Relevant Pages

  • RE: Determining max. length of text that can be entered for anothe
    ... string; the size I get back implies that all of the text in the text box will ... fit into the label box w/o clipping, ... Dim stringFont As New Font ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Strings and symbols
    ... See, the label on each push-button is a string, not a symbol. ... and thus "interning" the resulting symbol. ... concatenating doesn't do interning so it wouldn't "thus" intern the ...
    (comp.lang.lisp)
  • Re: Best Method
    ... dim dcfirstcolumn as new datacolumn ... >> first field would be a string... ... > Private _Label As String = String.Empty ... > Public Sub New(ByVal label As String, ByVal theDate As DateTime) ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Printing data horizontally instead of vertically on label
    ... To place items of an order across the top of a label or report in the first ... concatenate multiple records into a single string ... Place multiple text box controls across the top of the Report/Label like so: ...
    (microsoft.public.access.reports)
  • ghdl problem
    ... I'm trying to use ghdl to model the pacman vhdl source which can be found ... function romgen_str2bv (str: string) return bit_vector is ... attribute INIT_00 of inst: label is ...
    (comp.lang.vhdl)