Path: utzoo!utgpu!water!watmath!clyde!att!pacbell!ames!husc6!cca!g-rh
From: g-rh@cca.CCA.COM (Richard Harter)
Newsgroups: comp.std.c
Subject: Re: switch (expression)
Message-ID: <30937@cca.CCA.COM>
Date: 15 Jul 88 01:44:55 GMT
References: <1988Jul12.105547.13268@light.uucp> <7329@cup.portal.com> <12484@mimsy.UUCP>
Reply-To: g-rh@CCA.CCA.COM (Richard Harter)
Organization: Computer Corp. of America, Cambridge, MA
Lines: 26

In article <12484@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:

>A more general version appears in Mesa:

    SELECT expression FROM
    { expression => statements }*
    END

>(syntax very approximate).  All `expression's are arbitrary; the
>language is defined such that the first `expr =>' that matches the
>selected expression takes effect.  It is up to the optimiser to notice
>that all the `expr =>'s are constant (if indeed they are) and turn this
>into a computed goto; if some of the `expr's are non-constant, the
>whole thing must usually be compiled as a series of if/else tests.

Turning a list of constants into a form suitable for a computed goto
is non trivial if the constants are widely scattered in value.  A smart
compiler could construct a hash table to map the constants into a tight
integer range.  If the compiler does do this, then the SELECT-FROM-END
construct will produce code superior to that likely to be produced by
a human being when you have a long list.
-- 

In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
	Richard Harter, SMDS  Inc.