🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9158

Re: generalized switch

#9158
From: Stuart D. Gathman
Date: Tue, 19 Aug 1986 01:11
17 lines
1547 bytes
In article <1083@inset.UUCP>, dave@inset.UUCP (Dave Lukes) writes:

> >specify open-ended ranges, to allow things like "switch (strcmp(s, t)) {
> >case LT: ... case EQ: ... case GT: ... }" where LT and GT are #define'd as
> 
> What's wrong with ``if''??

'if' requires the result of strcmp() to be stored in a register or else
evaluated twice.  i.e.  { if ((r = strcmp(s,t)) < 0) less(); else if (r == 0)
same(); else more(); }  Try writing a balanced binary tree routine.  Storing
the result in a register is certain to be at least as efficient as any
implementation of open ended ranges, however.  The switch does look a lot
neater; of course, if people restricted their compares to return -1,0,1
there would be no problem.  Also, open ended ranges need not be implemented
in the compiler since macros like MAXINT are available.  Ranges should
not be a problem, though; many compilers already convert adjacent cases
to ranges so that a jump table can be used.
Technical Details
Message-ID: <158@BMS-AT.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!rlgvax!vrdxhq!BMS-AT!stuart
References: <15093@ucbvax.BERKELEY.EDU> <86900006@haddock> <1083@inset.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!rlgvax!vrdxhq!BMS-AT!stuart
From: stuart@BMS-AT.UUCP (Stuart D. Gathman)
Newsgroups: net.lang.c
Subject: Re: generalized switch
Message-ID: <158@BMS-AT.UUCP>
Date: Mon, 18-Aug-86 21:11:51 EDT
Article-I.D.: BMS-AT.158
Posted: Mon Aug 18 21:11:51 1986
Date-Received: Wed, 20-Aug-86 22:44:05 EDT
References: <15093@ucbvax.BERKELEY.EDU> <86900006@haddock> <1083@inset.UUCP>
Organization: Business Management Systems, Inc., Fairfax, VA
Lines: 17
Summary: This is what for. . .