switch...case without break;

Posted By: Lukas

switch...case without break; - 06/27/10 19:03

I found out that in Lite-C, a switch...case without break doesn't behave like in standard C/C++. You can see that in this example:

Code:
#include <acknex.h>

var x;
void main ()
{
	while (1)
	{
		x = 0;
		switch(key_lastpressed)
		{
			case 16: // q
			x += 1;
			case 17: // w
			x +=10;
			case 18: case 19: // e or r
			x+=100;
			break;
		}
		wait(1);
	}
}

PANEL* debug_pan =
{
	digits(10,10,"%f",*,1,x);
	flags = SHOW;
}



In standard C/C++, the code shouldn't be stopped being executed if there is no break, but a new case. This means, when you press Q, x should be 111, but it's 1! It seems that Lite-C stops at the next case. But the E and R key behave the same, so it seems that it doesn't stop if there is no code inbetween. If this is some kind of "noob-protection", in case the user forgot a break; please make a define or something to turn it off.

Also, an empty switch...case, like this
Code:
switch(something)
{

}


returns a syntax error. It also returns a syntax error if there is only a default case. It would be nice if the compiler didn't give an error, because sometimes it can be useful to comment out some cases for debugging and it's just annoying if you comment out the last not commented case and you get an error and have to comment out the whole switch.


This happens with 7.85 and 8.00.6.
Posted By: Lukas

Re: switch...case without break; - 11/19/10 20:57

Bump.
Posted By: jcl

Re: switch...case without break; - 11/22/10 14:40

Thanks, I have somehow overlooked this.

There seems indeed something to be non-standard with switch/case. We'll check if this can be corrected quickly, otherwise it will be documented.
Posted By: Lukas

Re: switch...case without break; - 11/22/10 15:54

Ok, thanks.
Posted By: Lukas

Re: switch...case without break; - 12/13/10 11:49

Any news about this?
Posted By: jcl

Re: switch...case without break; - 12/13/10 12:23

We have a list of similar small issues for the compiler - they'll all be addressed when the next compiler improvement step is due.
Posted By: Lukas

Re: switch...case without break; - 12/13/10 13:31

Ok...
© 2024 lite-C Forums