Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!nike!ucbcad!ucbvax!ernie.Berkeley.EDU!kos From: kos@ernie.Berkeley.EDU (Joshua Kosman) Newsgroups: net.lang.c Subject: Re: generalized switch Message-ID: <15120@ucbvax.BERKELEY.EDU> Date: Sun, 3-Aug-86 19:46:32 EDT Article-I.D.: ucbvax.15120 Posted: Sun Aug 3 19:46:32 1986 Date-Received: Mon, 4-Aug-86 01:31:44 EDT References: <15093@ucbvax.BERKELEY.EDU> <2765@brl-smoke.ARPA> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: kos@ernie.Berkeley.EDU.UUCP (Joshua Kosman) Organization: University of California, Berkeley Lines: 39 In article <2765@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >In article <15093@ucbvax.BERKELEY.EDU> kos@ernie.Berkeley.EDU (Joshua Kosman) writes: >> switch() { >> case : >> etc. >> } >>... >>Any ideas? > >In C, such code is written: > > if ( bool_expr_1 ) > action_1 > else if ( bool_expr_2 ) > action_2 > else if ... > else > default_action > >You could come up with some CPP macros for this, but why bother? Sure, that's the way I have been doing it. But you can do that with any choice among cases. 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 any case, it can be rewritten that way. But the switch promotes comprehensibility. The situation I find (mildly) frustrating is when I have a choice among cases, a setup which is conceptually akin to a switch, but is not syntactically equivalent because I want to use a slightly different test than simple equality. Joshua Kosman || "When I was young people used to tell me, kos@ernie.berkeley.EDU || 'When you're 50 you'll understand.' Well, Dept. of Music || now I'm 50. I don't understand a thing." UC Berkeley || -- Erik Satie