什么是间接 goto 语句?

What is an indirect goto statement?

在 Clang API 中,有一个 GotoStmt and an IndirectGotoStmt。关于这两种 goto 语句之间的区别的解释很少。我知道什么是 goto label; 语句。但是什么是 间接 goto 语句 ?我想知道在 C/C++ 代码的上下文中是什么,不一定只是 Clang。 间接 goto 语句 在句法上意味着什么?你能提供一个代码示例吗?

编辑:下面这个问题很有意思。

有一个 GNU 扩展允许获取标签的地址,存储它供以后使用,然后 goto 该地址在以后使用。有关详细信息,请参阅 https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html。示例:

    void *ptr;

    if(...)
        ptr = &&foo;
    else
        ptr = &&bar;

    /* ... */
    goto *ptr;

foo:
    /* ... */

bar:
    /* ... */

Clang 也支持它,因为它旨在与 GCC 兼容。

例如,上述内容可能用于实现状态机。