Hello, I was working on a ARM project with my Keil toolchain, and by chance I just found that the following code is working (see case 2); I tested it in the ARM simulator using different values for alfa and beta. Someone knows where can I find more detailed explanation about this behaviour of C language (K&R say nothing about "case" into "if"...)? Thanks in advance. Bruno
char alfa; char beta; char zeta; int main (void) { while (1) { switch (alfa) { case 0: zeta = 17; break; case 1: zeta = 91; break; case 2: if (beta == 1) { case 3: zeta = 38; break; case 4: zeta = 47; } break; } } }
I only have H&S and the standard handy at the moment. The code is valid, is dealt with in H&S, and isn't disallowed by the standard. 'switch' is essentially a computed 'goto', so why shouldn't it work? Whether it's good form or not is another question.
If you're not sure what something should do, how can you be sure that what it does actually (appear to) do constitutes "working"...?
View all questions in Keil forum