C
Christopher Benson-Manica
I presume that putting the default case of a switch statement before
the others is legal, as in the following skeleton program:
#include <stdio.h>
int main( int argc, char *argv[] )
{
switch( (unsigned int)argc ) { /* just to be pedantically correct */
default:
printf( "%d arguments not handled...\n", argc-4 );
case 4:
/* do stuff with argv[3] */
case 3:
/* do stuff with argv[2] */
case 2:
/* do stuff with argv[1] */
case 1:
/* do stuff with argv[0] */
case 0:
/* do nothing */
break;
}
return 0;
}
If it is legal, is it stylistically acceptable and reasonably easy to
understand? (I have my doubts.)
the others is legal, as in the following skeleton program:
#include <stdio.h>
int main( int argc, char *argv[] )
{
switch( (unsigned int)argc ) { /* just to be pedantically correct */
default:
printf( "%d arguments not handled...\n", argc-4 );
case 4:
/* do stuff with argv[3] */
case 3:
/* do stuff with argv[2] */
case 2:
/* do stuff with argv[1] */
case 1:
/* do stuff with argv[0] */
case 0:
/* do nothing */
break;
}
return 0;
}
If it is legal, is it stylistically acceptable and reasonably easy to
understand? (I have my doubts.)