This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Parsing of switch statement



> 	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.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]