Use the following example, for instance.
void *ptr; ... ptr = &&foo;To use these values, you need to be able to jump to one. This is done with the computed goto statement, goto * exp; as in goto *ptr;. The analogous feature in FORTRAN is called an assigned goto, but that name seems inappropriate in C, where one can do more than simply store label addresses in label variables.
Any expression of type void * is allowed.
One way of using these constants is in initializing a static array that will serve as a jump table:
static void *array[] = { &&foo, &&bar, &&hack };Then you can select a label with indexing, as in the following example.
goto *array[i];.Note:
Another use of label values is in an interpreter for threaded code. The labels within the interpreter function can be stored in the threaded code for super-fast dispatching.
You can use this mechanism to jump to code in a different function. If you do that, totally unpredictable things will happen. The best way to avoid this is to store the label address only in automatic variables and never pass it as an argument.