Mail Archives: djgpp/1998/02/11/00:33:47
At 08:34 2/10/1998 GMT, Linh Nguyen wrote:
>Hi. I use Borland C++ 5 at school, and coded the switch statement as
>follows...
>
>switch(Num)
>{
>case 1, 10, 6: cout << "Test"; break;
>....... and so on and so forth
>}
That is a nonstandard extension made by Borland. It is not part of Standard
ANSI C, so if you use it your program is not portable.
>
>but in DJGPP, it won't let me do that, it only lets me have one
>possibility for each case statement, so it would be like this..
>
>case 1: ...
>case 10: ...
>case 6: ...
That's correct. However, since by default in C a `switch' case falls
through, you can do this:
switch(foo)
{
case 1:
case 10:
case 6:
cout << "Test";
break;
/* ... */
}
GCC does provide an extension to let you use ranges in `case' expressions,
so that
case 1 ... 4: /* stuff */
is equivalent to:
case 1:
case 2:
case 3:
case 4: /* stuff */
See the info page "gcc" "C Extensions" "Case Ranges" for more info and
caveats. Note that this also is not standard.
>
>Is there any way around this? Thanks for any help!
>
>
>
Nate Eldredge
eldredge AT ap DOT net
- Raw text -