From the manual:
Originally Posted By: goto label
The target label must be within the same winged brackets ({ .. }) as the goto instruction.
This is unusual, as far as I've seen in C and C++ -- normally the only requirement is that the label is within the same function.

I know use of goto is normally frowned upon, but consider the following small piece of code:
Code:
int i, j, k;
for (i=0; i<4; i++) {
	for (j=i+1; j<4; j++) {
		for (k=j+1; k<4; k++) {
			... do stuff ...
			goto foundFace;
		}
	}
}
foundFace:
...

We have some nested loops, in this case to consider the faces of a tetrahedron and stop as soon as we find a face that fits certain conditions. Normally we'd exit a loop with "break", but the only way to do so here would be to have a "break" within each loop, and set another variable to indicate it's time to break, which each loop would check, so it might as well be included as an extra condition in all but the inner-most loop. That's ugly and a little inefficient. Another option would be to put all the loops in a separate function, and use "return" instead of "goto", but this is the only instance where I need these loops since they serve a very specific purpose, and calling a new function for this purpose would be inefficient.

Yes, if I'm so concerned about efficiency I could unroll the loops. But that's not the problem -- it's the balance of efficiency and readability, and the use of "goto" is the most readable in this case. "goto" can lead to spaghetti code, but it can also be used as a deep "break".

So yeah, between the other stuff you guys have going on, if it's not too much trouble, I think it'd be nice if Lite-C was a little more C-like in this regard -- "goto" shouldn't be confined to a label in the same set of winged brackets laugh


Formerly known as JulzMighty.
I made KarBOOM!