Just as C borrowed the fall-through flavored switch from BCPL, I think
the idea for varying code generation came from there as well, so you
might want to track down the Richards/Whitby-Strevens book on BCPL.

The choice will depend on the number and density of the case values
("density" meaning "how close together they are"), and also the target
instruction set. Handwaving heavily, if values are few, one might as
well do linear search; for more cases, high density lends itself to a
jump table, lower to binary search. If one wishes to get more
sophisticated, one might look for cases in which it's worth checking
for a few outliers and then going to a jump table.

James Jones

mayur_naik@my-deja.com wrote:> Could any one give me references to web-sites / papers / books> which discuss the optimization of the "switch" stmt in C?