Elipses是否为case语句标准C / C ++

我正在浏览linux内核中的一些代码,我遇到了像case '0' ... '9':这样的语句case '0' ... '9':

为了试试这个,我在下面创建了测试程序。

 #include  int main() { const int k = 15; switch (k) { case 0 ... 10: std::cout << "k is less than 10" << std::endl; break; case 11 ... 100: std::cout << "k is between 11 and 100" << std::endl; break; default: std::cout << "k greater than 100" << std::endl; break; } } 

上面的程序确实编译了,虽然我之前从未遇到过case语句构造中的elipses。 这个标准的C和C ++还是这个语言的GNU特定扩展?

这是GNU C编译器的案例范围扩展,它不是标准的C或C ++。

这是一个扩展。 用-pedantic编译你的程序给出:

 example.cpp: In function 'int main()': example.cpp:9: error: range expressions in switch statements are non-standard example.cpp:12: error: range expressions in switch statements are non-standard 

clang给出了更好的警告:

 example.cpp:9:12: warning: use of GNU case range extension [-Wgnu] case 0 ... 10: ^ example.cpp:12:13: warning: use of GNU case range extension [-Wgnu] case 11 ... 100: ^ 

这是C的GCC扩展,在这个基本上是重复问题的答案中提到,并在GCC文档中得到确认。