switch case failure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JimS

    #16
    Re: switch case failure

    On Tue, 11 Oct 2005 15:21:58 -0400, "Steve Fábián"
    <ESFabian@BellA tlantic.net> wrote:
    [color=blue][color=green][color=darkred]
    >>>> switch (n)
    >>>> {
    >>>> case 1..3:
    >>>> // do thing A
    >>>> break;
    >>>> case 4:
    >>>> // do thing B
    >>>> break;
    >>>> default:
    >>>> // do thing C
    >>>> }
    >>> I would tend to agree. My guess would be that they didn't want to change
    >>> the same construct too much from the original C version. But that's just
    >>> a guess, you'd have to ask the committee.
    >>>[/color]
    >> My guess is that for this minimum comfort we get a can of worms in the
    >> parser design. . .[/color]
    >
    >It is a "minimum comfort" if the range is 1..3, but not if it is 1005..11004
    >(you'd not like to list them as individual cases,would you). Yes, I know you
    >can do it with an "if" instead, but if/elseif/elseif/elseif... is far less
    >clear to the person validating the code.
    >
    >Personally, I'd like to see the "select first/select all" I mentioned before
    >(with the ranges).[/color]

    The problem is that you can't use 1..3 or 1...3 because then the way C
    parsers work it will look like 1. which is a floating point number.
    In GCC's case-range extension it has to look like 1 ... 3

    You can always use a combination of switch/if/else, or if it all gets
    a bit too hairy, use a jump table.

    JimS

    Comment

    Working...