about goto

  • Thread starter Thread starter Abubakar
  • Start date Start date
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
 
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.
 
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.
 
Back
Top