Pelles C forum
C language => Beginner questions => Topic started by: Alessio on October 06, 2009, 01:06:33 PM
-
Hi,
please see this code:
//
#include <stdio.h>
//
int main(void)
{
//
int i;
//
for ( i = 0; i < 10; i++ )
{
switch ( i )
{
case 0:
case 1:
case 2:
case 5:
printf("%d is in case!\n", i);
break;
default:
printf("%d is NOT in case!\n", i);
break;
}
}
return 0;
}
Why I get this output ?
0 is in case!
1 is in case!
2 is in case!
3 is in case!
4 is in case!
5 is in case!
6 is NOT in case!
7 is NOT in case!
8 is NOT in case!
9 is NOT in case!
Why 3, 4 is "in case" ?
Thanks,
Alessio.
-
In C you need a break in each case unless you want fall-through.
case 0:
break;
EDIT: sorry I see what you are saying - the answer is I don't know. I've checked with previous versions of PellesC and get the same result.
EDIT1:
It would appear that PellesC is is not generating the right code. I've checked with two other compilers which both give the result you expect.
John
-
Thank you.
Should this topic moved to bug reports ?
-
I think so yes.
John