I found a long-standing bug is some code (I had written the code, so my it's own fault). The thing that I cannot understand is why it was not spotted by the compiler.
The code is in C, which I have been using for many years and I always consider myself knowledgeable about, but it makes no sense to me. I have tried similar code under both Visual Studio and Gnu C compilers and both accept it.
The code is:
enum TYPE_ENUMS {
TEST_CASE = 1,
};
int main()
{
int caseVal = 1;
switch (caseVal) {
TEST_CASE:
printf("1\n");
default:
printf("Unknown Case %d\n", caseVal);
break;
}
}
Can anyone explain how an enum can be part of a case statement without a "case" before it. Should this be valid code? and if so, is there a use for it?