I faced with new for me C/C++ switch/if/else/case syntax. I can't find it's mention in C standart. Value inside "if" doesn't matter, "if(1)" or "if(0)" works same. Seems this "if" doesn't act like condition, but as scope. Is it compiler extension or compiler sugar ?
#include <stdio.h>
int main()
{
int a = 0, b = -1, c = -1;
switch(a)
{
if(1) {
case 0: b = 0;
printf("%u:b=%d\n", __LINE__, b);
}
else if(0) {
case 1: b = 1;
printf("%u:b=%d\n", __LINE__, b);
}
else if(0) {
case 2: b = 2;
printf("%u:b=%d\n", __LINE__, b);
}
else {
case 3: b = 3;
printf("%u:b=%d\n", __LINE__, b);
}
c = 0;
printf("%u:b=%d, c=%d\n", __LINE__, b, c);
break;
}
printf("b=%d", b);
return 0;
}