generalized switch
Mike Schloss
mike at enmasse.UUCP
Thu Aug 14 13:49:46 AEST 1986
->[Discussion about switch versus if/elseif]
->> As I understand it, a switch/case setup compiles exactly the same as
->> if (var == const1) {.....};
->> else if (var == const2) {.....};
->> else {default_action};
->> anyway. (Or am i wrong?).
->
->In a way. They are the same in the sense that i=i+j and i+=j are the
->same. The switch expression is evaluated only once, which can be
->important:
->
-> switch (*bufp++)
One other difference is that case statements are optimized by some compilers
to use jump tables and such so they can be much more efficient than repeated
if/else statements.
More information about the Comp.lang.c
mailing list