使用“ ...”选择枚举元素。 [英] Choosing enum element using "..."

查看:83
本文介绍了使用“ ...”选择枚举元素。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

...符号是c语言关键字吗?

Is '...' symbol is a c language keyword?

代码:

#include <stdio.h>

typedef enum {
    A=0,B,C,D,E,F,G,H,I,J,K,M
} alpha;


int main(int argc, char const *argv[])
{


    alpha table = C;

    switch (table)
    {
        case A ... D:
        /* I have never seen "..." grammar in textbook */
            printf("Oh my god\n");
            break;
        default:
            printf("default\n");
            break;
    }
    return 0;
}

...

Is ... allowed in C for range?

推荐答案

不是标准C,而是GCC扩展名:

It's not standard C, but a GCC extension:


您可以在单个大小写标签中指定一系列连续值,例如:

You can specify a range of consecutive values in a single case label, like this:

case low ... high:

与适当大小写的个案标签具有相同的效果,从低到高各为一个整数到最高的包容性。

This has the same effect as the proper number of individual case labels, one for each integer value from low to high, inclusive.

更多 GCC扩展名:案例范围

这篇关于使用“ ...”选择枚举元素。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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