Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!unmvax!bbx!bbxsda!scott From: scott@bbxsda.UUCP (Scott Amspoker) Newsgroups: comp.lang.c Subject: Re: New super switch, was Re: The final word on GOTO Keywords: switch case cases goto Message-ID: <219@bbxsda.UUCP> Date: 9 Oct 89 15:20:14 GMT References: <6396@ficc.uu.net> <725@thor.wright.EDU> <6430@ficc.uu.net> <4447@buengc.BU.EDU> <867@crdos1.crd.ge.COM> <4462@buengc.BU.EDU> <4467@buengc.BU.EDU> <29947@watmath.waterloo.edu> <180@jabberwock.shs.ohio-state.edu> Reply-To: scott@bbxsda.UUCP (Scott Amspoker) Distribution: na Organization: Basis International, Albuquerque, NM Lines: 26 In article <180@jabberwock.shs.ohio-state.edu> Michel Jackson writes: >In the companion volume, _Numerical Recipes in C_ (yes, i have & use >both ...), they remark > > In C, the most dubious control structure is the switch...case...default > construction, recognizable to FORTRAN programmers as a kind of elaborate > "computed goto". Not only is the structure a confusing one, with a > bizarre "drop through" feature, it is also burdened with uncertainty, > from compiler to compiler, about what data types are allowed in its > control expression. It can virtually always be easily replaced by a > more recognizable and translatable if ...else construction. (p.13) This was the point when reading "Numerical Recipies in C" that I seriously lost faith in the authors of the book. I'm sure their math background is solid but their FORTRAN mentality made for very bad C. There is a BIG difference between a switch statement and multple if-elses. A switch statement is a multi-way branch. A switch statement with more than a trivial number of cases is almost guaranteed to be implemented as a jump table. It is not unusual for us to have switch statements with 50 or more cases. To do the same thing with multiple if-elses would seriously degrade performance as well as obscure the meaning of the code. -- Scott Amspoker Basis International, Albuquerque, NM (505) 345-5232