The D Programming Language: switches
Richard Tobin
richard at aiva.ed.ac.uk
Wed Mar 23 09:05:25 AEST 1988
In article <25835 at cca.CCA.COM> g-rh at CCA.CCA.COM.UUCP (Richard Harter) writes:
> Theoretically the switch construct is more powerful than an else-if
>chain because it selects in one step. Execution is O(1) rather than O(n)
>where n is the number of branches.
No, *practically* the switch construct is more powerful because it selects
in one step. *Theoretically* switch can compile into an if-then-else chain
(and often will, if the case values are widely separated), and an
if-then-else chain can be analysed to discover whether it can be compiled
into a jump table.
The theoretical power of a language is [determined by] the set of
algorithms it can implement. Its efficiency in executing these algorithms
depends on its implementation, though it's obviously easier to produce
efficient implementations of some languages than others.
--
Richard Tobin, JANET: R.Tobin at uk.ac.ed
AI Applications Institute, ARPA: R.Tobin%uk.ac.ed at nss.cs.ucl.ac.uk
Edinburgh University. UUCP: ...!ukc!ed.ac.uk!R.Tobin
More information about the Comp.lang.c
mailing list