C语言goto跳转的一个特殊的方式,记录发现的问题

今天遇见了一个这样样的写法,来实现goto,感觉很棒,看代码能看出来大概实现,但是为什么能这样实现不太清楚,有没有感兴趣的大佬指点一下迷津。为什么可以这样实现。

我的理解: 对DROP取二级地址放到指针数组里面,元素1号位置是DROP这个字符串的二级地址,然后对元素 * 解引用,就可以输出地址里面的东西就是DROP。
我的疑问:1.这个数组为什么可以这样定义呢?2.为什么printf打印不出来table的元素呢?

#include <stdio.h>

int main ()
{
        static const void *table[10] = {
                NULL,
                &&DROP,
                &&ADVANCE,
                &&UPF_QER,
                &&UPF_URR,
                &&UPF_ENCAP_IP4,
                &&UPF_ENCAP_IP6,
                &&UPF_FOW_FIB,
                &&END};
        int type;
        while(1){
        scanf("%d", &type);
        goto *(table[type]);

DROP:
        printf("type : %d\n", type);
        continue;
ADVANCE:
        printf("type : %d\n", type);
        continue;
UPF_QER:
        printf("type : %d\n", type);
        continue;
UPF_URR:
        printf("type : %d\n", type);
        continue;
UPF_ENCAP_IP4:
        printf("type : %d\n", type);
        continue;
UPF_ENCAP_IP6:
        printf("type : %d\n", type);
        continue;
UPF_FOW_FIB:
        printf("type : %d\n", type);
        continue;
END:
        printf("type : %d\n", type);
        continue;
        }
        return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值