//===================
switch (a)
{
case 1 ... 10:
//do somthing
break;
case 11 ... 20:
//do somthing
break;
default:
//do something
break;
}
//===================
This is successfully with gcc compiler.
But not done with VC++
That's because Standard C doesn't support switch-case with range.
I found the answer from http://c-faq.com/misc/nonconstcase.html
If using gcc with option -pedantic,
then will be error occur when compile like below:
warning: range expressions in switch statements are non-standard
unless you are clarify what are you doing, and understand the code portable issue.
DONOT using switch-case with range! (my own suggestion...)
2011/09/26
[C/C++]switch-case with range?
There is an interesting discussed after today study group.
Is C/C++ support switch-case with range of integer!?
Let see a example :
訂閱:
意見 (Atom)