Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!harvard!panda!enmasse!mike From: mike@enmasse.UUCP (Mike Schloss) Newsgroups: net.lang.c Subject: Re: generalized switch Message-ID: <354@enmasse.UUCP> Date: Wed, 13-Aug-86 23:49:46 EDT Article-I.D.: enmasse.354 Posted: Wed Aug 13 23:49:46 1986 Date-Received: Thu, 14-Aug-86 08:27:54 EDT References: <15093@ucbvax.BERKELEY.EDU> <2765@brl-smoke.ARPA> <15120@ucbvax.BERKELEY.EDU> <480@mcgill-vision.UUCP> Reply-To: mike@enmasse.UUCP (Mike Schloss) Organization: EnMasse Computer Corp, Acton, MA Lines: 16 ->[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.