1

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

The code:

#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?

Sourav Ghosh
  • 130,437
  • 16
  • 177
  • 247
myanl
  • 125
  • 9

2 Answers2

2

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.

More in GCC extension: Case ranges

Community
  • 1
  • 1
Yu Hao
  • 115,525
  • 42
  • 225
  • 281
1

This is called Case Ranges. And no, this is not a standard C feature.

It is implemented as gcc extension. This is just another way to use fall-through case statement.

Sourav Ghosh
  • 130,437
  • 16
  • 177
  • 247