You can only put constant values in case statements. Your compiler considers that "abcd"[1] is not a constant. But you can still do a case 'b' instead.
String literals aren't ready to be used as arrays until translation phase 7. It is not unreasonable to conclude that the "syntactic and semantic analysis" in translation phase 7 is when case argument error messages are generated. Perhaps the issue is that the Standard doesn't mandate the order of translation phase 7 activities. Perhaps the error will go away if you use a different compiler. If so, then that would be relying on implementation-defined behavior, which is not a good idea.
From the C99 Standard (regarding string literals and constant expressions):
6.4.5 String literals
...
4 In translation phase 6, the multibyte character sequences specified by any sequence of adjacent character and wide string literal tokens are concatenated into a single multibyte character sequence. If any of the tokens are wide string literal tokens, the resulting multibyte character sequence is treated as a wide string literal, otherwise it is treated as a character string literal.
5 In translation phase 7, a byte or code of value zero is appended to each multibyte character sequence that results from a string literal of literals. The multibyte character sequence is then used to initialize an array of static storage duration and length just sufficient to contain the sequence. For character string literals, the array elements have type char, and are initialized with the individual bytes of the multibyte character sequence; for wide string literals, the array elements have type wchar_t, and are initialized with the sequence of wide characters corresponding to the multibyte character sequence, as defined by the mbstowcs function with an implementation-defined current locale. The value of a string literal containing a multibyte character or escape sequence not represented in the execution character set is implementation-defined.
6.6 Constant expressions
...
2 A constant expression can be evaluated during translation rather than runtime, and accordingly may be used in any place that a constant may be.
...
6 An integer constant expression shall have integer type and shall only have operands that are integer constants, enumeration constants, character constants, sizeof expressions whose results are integer constants, and floating constants that are the immediate operands of casts. Cast operators in an integer constant expression shall only convert arithmetic types to integer types, except as part of an operand to the sizeof operator.
From the C99 Standard (regarding translation phases):
5.1.1.2 Translation phases
The precedence among the syntax rules of translation is specified by the following phases.
...
5. Each source character set member and escape sequence in character constants and string literals is converted to the corresponding member of the execution character set; if there is no corresponding member, it is converted to an implementation-defined member other than the null (wide) character.
6. Adjacent string literal tokens are concatenated.
7. White-space characters separating tokens are no longer significant. Each preprocessing token is converted into a token. The resulting tokens are syntactically and semantically analyzed and translated as a translation unit.
8. All external object and function references are resolved. Library components are linked to satisfy external references to functions and objects not defined in the current translation. All such translator output is collected into a program image which contains information needed for execution in its execution environment.
By the way, what are you trying to accomplish with "switch (0)"?
Nothing... that was just a simple way of showing, in response to the first reply, that "abcd"[1] is *not* recognised (by gcc) as a constant integer expression. All this stuff is really in a too-complex-to-post-macro.
@donbock :
where did you get that C++ C99 standard ? I tried to get it (rev 2003) from the ISO certification web site (free since the new standard came out) but the document download fails...
Comment