switch (expression)
Richard Harter
g-rh at cca.CCA.COM
Fri Jul 15 11:44:55 AEST 1988
In article <12484 at mimsy.UUCP> chris at 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.
More information about the Comp.std.c
mailing list