Software, technology, sysadmin war stories, and more. Feed
Thursday, September 27, 2012

Magic GOTO for great justice

C++ programmers, I have a question for you. Would you ever do something like this almost-C++ pseudocode?

static void f3() {
  goto x;
static void f2() {
static void f1() {
  x: printf("all done\n");
int main() {
  return 0;

You can't actually do that in C++ since labels have function level scope. I had to look this up, since I never use the things.

To be clear, the question is: if you could do it, would you?

I would hope that you'd say "no", since jumping out of those functions would leave crazy things happening on the stack. It would be like doing a bunch of GOSUBs and then using a GOTO (!) to keep on running back in the days of BASIC. Sure, it probably works a couple of times, but sooner or later things blow up.

So, second question. Assume that it's magic and it knows to clean up the stack calls and all of that when it jumps from f3 right back into f1. What about then? Is that enough assurance to get you on board?

Does anyone see what I'm getting at yet?

September 28, 2012: This post has an update.