问题
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?
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/37318196/choosing-enum-element-using