Path: utzoo!mnetor!uunet!mcvax!ukc!its63b!aiva!richard From: richard@aiva.ed.ac.uk (Richard Tobin) Newsgroups: comp.lang.c Subject: Re: The D Programming Language: switches Message-ID: <298@aiva.ed.ac.uk> Date: 22 Mar 88 23:05:25 GMT References: <222965b9@ralf.home> <941@micomvax.UUCP> <3074@haddock.ISC.COM> <25835@cca.CCA.COM> Reply-To: richard@uk.ac.ed.aiva (Richard Tobin) Organization: Bannerman's Bar, Cowgate, Edinburgh Lines: 19 In article <25835@cca.CCA.COM> g-rh@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@uk.ac.ed AI Applications Institute, ARPA: R.Tobin%uk.ac.ed@nss.cs.ucl.ac.uk Edinburgh University. UUCP: ...!ukc!ed.ac.uk!R.Tobin