In Clang API, there is a GotoStmt
and an IndirectGotoStmt
. There is very little explanation on the difference between these two kinds of goto statments. I know what a goto label;
statement is. But what is an indirect goto statement? I want to know what that is in the context of C/C++ code, not necessarily just Clang. What does it mean syntactically to have an indirect goto statement? Can you provide a code example?
Edit: The following question is interesting.
Can you make a computed goto in C++
A goto statement is allowed to jump within the scope of a variable length array, but not past any declarations of objects with variably modified types. The following example shows a goto statement that is used to jump out of a nested loop. This function could be written without using a goto statement.
There are two different styles of implementing the goto statement in C: Transferring the control from down to the top. Transferring the control from top to down.
The goto statement is a jump statement which is sometimes also referred to as unconditional jump statement. The goto statement can be used to jump from anywhere to anywhere within a function.
From the early days of programming (i.e. assembler programming) the replacement for goto directives is so-called structured programming. This means using if-then-else statements, for- and while-loops, switch statements, break and continue, etc.
There is a GNU extension that allows taking an address of a label, storing it for later use, then goto
that address at a later point. See https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html for details. Example:
void *ptr;
if(...)
ptr = &&foo;
else
ptr = &&bar;
/* ... */
goto *ptr;
foo:
/* ... */
bar:
/* ... */
Clang supports that too, as it aims at being compatible with GCC.
The use of the above might be, for example, in implementing state machines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With