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

问题描述

...符号是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:

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.

更多

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

10-19 20:30