Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!snorkelwacker!ai-lab!rpk From: rpk@wheaties.ai.mit.edu (Robert Krajewski) Newsgroups: comp.std.c++ Subject: Re: case() Summary: switch is a laggard compared to the rest of C++ Keywords: case statement Message-ID: <9907@rice-chex.ai.mit.edu> Date: 15 Aug 90 01:10:10 GMT References: <26842@pasteur.Berkeley.EDU> <26857@pasteur.Berkeley.EDU> <56515@microsoft.UUCP> <962@bbxsda.UUCP> Reply-To: rpk@rice-chex.ai.mit.edu (Robert Krajewski) Organization: MIT Artificial Intelligence Laboratory Lines: 25 In article <962@bbxsda.UUCP> scott@bbxsda.UUCP (Scott Amspoker) writes: >I disagree. A series of 'if' statements implies a sequence of tests >to be performed. A 'switch' implies a multi-way branch in which any >of the possible case values are equally likely to occur. This can >be easily optimized by a compiler. Although the standard does not >mandate it, a switch statement is expected, in most cases, to be >implemented as a quick indirect-jump table. Let the compiler decide that, then. switch should just specify semantics. >It is not unusual to have switches with over 100 cases which would >not perform acceptably as a series of 'if' statements. Syntactical >sugar indeed! Well, there is one other benefit to switch: the switched thing is an expression, it is evaluated only once, right ? So you get a temporary for free if you need it. I would like to see switch be extended at least to cover data types for which == holds. It's unfortunate that case tags have to be constants, but I can live with that. -- Robert P. Krajewski Internet: rpk@ai.mit.edu ; Lotus: robert_krajewski.lotus@crd.dnet.lotus.com