[英]What is an indirect goto statement?
In Clang API, there is a GotoStmt
and an IndirectGotoStmt
. 在Clang API中,有一个GotoStmt
和一个IndirectGotoStmt
。 There is very little explanation on the difference between these two kinds of goto statments. 关于这两种goto语句之间的区别,几乎没有什么解释。 I know what a goto label;
我知道什么是goto label;
statement is. 声明是。 But what is an indirect goto statement ? 但什么是间接goto声明 ? I want to know what that is in the context of C/C++ code, not necessarily just Clang. 我想知道在C / C ++代码的上下文中是什么,不一定只是Clang。 What does it mean syntactically to have an indirect goto statement ? 具有间接goto语句在语法上意味着什么? Can you provide a code example? 你能提供代码示例吗?
Edit: The following question is interesting. 编辑:以下问题很有趣。
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. 有一个GNU扩展,允许获取标签的地址,存储它以供以后使用,然后在以后goto
该地址。 See https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html for details. 有关详细信息,请参阅https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html 。 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. Clang也支持这一点,因为它旨在与GCC兼容。
The use of the above might be, for example, in implementing state machines. 例如,上述用途可能在于实现状态机。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.