如何存储goto标签在数组,然后跳转到他们? [英] How to store goto labels in an array and then jump to them?

查看:248
本文介绍了如何存储goto标签在数组,然后跳转到他们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要声明一个jumplabels数组。

I want to declare an array of "jumplabels".

然后我要跳转到这个数组中的jumplabel。

Then I want to jump to a "jumplabel" in this array.

但我不知道该怎么做。

它应该看起来像下面的代码:

It should look like the following code:

function()
{
    "gotolabel" s[3];
    s[0] = s0;
    s[1] = s1;
    s[2] = s2;

    s0:
    ....
    goto s[v];

    s1:
    ....
    goto s[v];

    s2:
    ....
    goto s[v];
}

有没有人知道如何执行此操作?

Does anyone have a idea how to perform this?

推荐答案

有可能使用GCC功能称为标签作为值

It is possible with GCC feature known as "labels as values".

void *s[3] = {&&s0, &&s1, &&s2};

if (n >= 0 && n <=2)
    goto *s[n];

s0:
...
s1:
...
s2:
...

它仅适用于GCC!

这篇关于如何存储goto标签在数组,然后跳转到他们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆