Are Elipses in case statements standard C/C++

前端 未结 3 1856
南旧
南旧 2020-12-03 14:36

I was browsing some code in the linux kernel and I came across the statements like case \'0\' ... \'9\':

To try this out I created the test program belo

3条回答
  •  鱼传尺愫
    2020-12-03 14:57

    That's an extension. Compiling your program with -pedantic gives:

    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 gives even better warnings:

    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:
                ^
    

提交回复
热议问题