I want to declare an array of \"jumplabels\".
Then I want to jump to a \"jumplabel\" in this array.
But I have not any idea how to do this.
It should
For a simple answer, instead of forcing compilers to do real stupid stuff, learn good programming practices.
There's no direct way to store code addresses to jump to in C. How about using switch.
#define jump(x) do{ label=x; goto jump_target; }while(0)
int label=START;
jump_target:
switch(label)
{
case START:
/* ... */
case LABEL_A:
/* ... */
}
You can find similar code produced by every stack-less parser / state machine generator. Such code is not easy to follow so unless it is generated code or your problem is most easily described by state machine I would recommend not do this.
Tokenizer? This looks like what gperf was made for. No really, take a look at it.
could you use function pointers instead of goto?
That way you can create an array of functions to call and call the appropriate one.
That's what switch
statements are for.
switch (var)
{
case 0:
/* ... */
break;
case 1:
/* ... */
break;
default:
/* ... */
break; /* not necessary here */
}
Note that it's not necessarily translated into a jump table by the compiler.
If you really want to build the jump table yourself, you could use a function pointers array.
In plain standard C, this not possible as far as I know. There is however an extension in the GCC compiler, documented here, that makes this possible.
The extension introduces the new operator &&
, to take the address of a label, which can then be used with the goto
statement.