Parsing of switch statement
Joe Buck
jbuck@synopsys.com
Wed Dec 10 15:53:00 GMT 1997
> Recently I have encountered some code that contains an empty case
> statement at the end of a switch (see example below).
Such code is neither legal C nor legal C++. I think it's an extension
to gcc; you shouldn't assume that all GNU C extensions will be available
in g++ (some clash with other C++ syntax, not sure about this one).
>
> Here is the simple test
>
> #include <stdio.h>
>
> int main (int argc, char *argv[])
> {
> int i=1;
> switch (i) {
> case 1 : printf ("1 ");
> case 0 : /* a ';' is needed here to compile with g++ */
> }
> printf ("\n");
> return 0;
> }
The ';' is needed with any C or C++ compiler other than gcc.
More information about the Gcc
mailing list