> >
riv...@gmail.com writes:
>
> > [snip]
>
> >> In crux, the question is if I can use a switch-case's case-colon as a
>
> >> label for goto or not?
>
> > [snip]
>
> >
>
> > No, you can't. The target of a goto must be a the name of a label
>
> > defined with the "identifer ": syntax; a case label doesn't qualify.
>
> >
>
> > You can always add labels as needed:
>
> <snip>
>
> > If you're implementing a finite state machine, I suggest either a switch
>
> > statement in a loop, where the switch executes some chunk of code
>
> > depending on the current state, *or* a sequence of labelled blocks with
>
> > gotos. (I personally prefer the former; for one thing, encoding the
>
> > current state in a variable rather than having it be implicit in the
>
> > current location in the program can be helpful). Mixing case labels and
>
> > gotos could easily get out of control.
>
There is a phenomenal amount of content in this thread, could you just give a 10 sentence summary of the consensus - if one exists?
Could you reword and expand claims in your post below by real examples where I indicate a need for clarity?
>
> It's a shame the committee never took up computed gotos. For complex state
>
> machines you often need to jump around. Sure, you can set the next state and
>
> break out of the switch statement. But often times code will be nested
>
> inside loops, so you need to use a goto, anyhow, to break out. And that goto
>
> often takes you back to the _top_ of some outer loop.
>
>
>
> Plus, if you care about performance, you want to try to thread your
>
> instructions to avoid the loop conditional. I suppose it's possible with
>
> switch statements, as long as your compiler is smart enough, but computed
>
> gotos make it so much easier.
>
>
>
> I've had some success with macro solutions which hide two
>
> implementations--one using switch and another computed gotos.
Could you or someone else give a real example?
> With GCC and
>
> clang computed goto machines are always significantly faster. (And I never
>
> use GCC's recommendation of storing label offsets, because that's a gigantic
>
> pain in the butt--impossible if you generate cases or labels with
>
> __LINE__--and in the age of C++ nobody will notice the insignicant link-time
>
> costs.)
Again, could you or someone else give a real example?