Path: utzoo!attcan!uunet!ginosko!uakari.primate.wisc.edu!uwm.edu!rutgers!tut.cis.ohio-state.edu!jabberwock.shs.ohio-state.edu!jackson From: jackson@jabberwock.shs.ohio-state.edu (Michel Jackson) Newsgroups: comp.lang.c Subject: Re: New super switch, was Re: The final word on GOTO Summary: switch/case/default dangerous to health Keywords: switch case cases goto Message-ID: <180@jabberwock.shs.ohio-state.edu> Date: 9 Oct 89 01:43:39 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> Reply-To: Michel Jackson Distribution: na Organization: The Ohio State University, Division of Speech and Hearing Science Lines: 34 Press, Flannery, Teukolsky, & Vetterling remark, in their very useful book _Numerical Recipes: The Art of Scientific Computing_ Every programming language has some number of "goodies" that the designer just couldn't resist throwing in ... In FORTRAN we consider the ill-advised control structures to be -assigned GOTO and ASSIGN statements - computed GOTO statement - arithmetic IF statemetn In Pascal an example is -CASE ... OF 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) I generally agree with them. Some of the most confusing code I have ever written relied on (long) switch statements and various drop throughs (exhaustive testing of a function that had some 8-10 arguments & needed to be demonstrated correct & also had to be shown to handle various combinations of incorrect inputs properly) ... i eventually gave up trying to debug my own code & rewrote it from scratch with a pile of if's. Surely adding "cases" will make switch statements even harder to figure out ... i must admit, though, that "tame" switch statements are a great convenience. ---michel jackson