New super switch, was Re: The final word on GOTO

Scott Amspoker scott at bbxsda.UUCP
Tue Oct 10 01:20:14 AEST 1989


In article <180 at jabberwock.shs.ohio-state.edu> Michel Jackson <jackson at cis.ohio-state.edu> 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



More information about the Comp.lang.c mailing list