about goto

A

Abubakar

Hi,
I got this code from some site:

#include <stdio.h>
int
main() {
int n = -1;
x0:
printf("%d\n" , ++n);
goto *(&&x0 + n/1000 * (&&x1 - &&x0));
x1:
return 0;
}

it doesnt compile successfully. Apparently the goto statement need a
hardcoded *label* for a correct compilation. The above code maybe written in
gcc i think. Am i right to say that this code cannot compile in vc?

regards,
...ab
 
B

Ben Voigt [C++ MVP]

Abubakar said:
Hi,
I got this code from some site:

#include <stdio.h>
int
main() {
int n = -1;
x0:
printf("%d\n" , ++n);
goto *(&&x0 + n/1000 * (&&x1 - &&x0));
x1:
return 0;
}

it doesnt compile successfully. Apparently the goto statement need a
hardcoded *label* for a correct compilation. The above code maybe written
in gcc i think. Am i right to say that this code cannot compile in vc?

Neither C nor C++ allow computed goto. Computed goto may have some
performance advantages over naive control structures, but the optimizing
compiler should generate code at least as fast as computed goto.
 
B

Ben Voigt [C++ MVP]

Ben Voigt said:
Neither C nor C++ allow computed goto. Computed goto may have some
performance advantages over naive control structures, but the optimizing
compiler should generate code at least as fast as computed goto.

Also note that an array of function pointers is possible in C (or C++), and
provides a computed gosub.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top