Article View: comp.std.c++
Article #313Re: case()
From: Scott Amspoker
Date: Mon, 13 Aug 1990 20:26
Date: Mon, 13 Aug 1990 20:26
38 lines
1890 bytes
1890 bytes
In article <56515@microsoft.UUCP> bobatk@microsoft.UUCP (Bob ATKINSON) writes: >In article <26857@pasteur.Berkeley.EDU> bilmes@icsib (Jeff Bilmes) writes: >>This does not warrant >>extending the language when you can do the semantic equivalent as >>easily as: >> >> if (exp == val1) >> s1 >> else if (exp == val2) >> s2 >> else if (exp == val3 || exp == val4 || exp == val5 || ...) >> s3 >> ... > >By this logic, switch statements should not have been invented >in the first place. Clearly in C a need was felt for this syntactic >sugar.... 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. 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! It is difficult to expand the multiway-jump concept to include non-integral values. In those cases, a switch statement really is nothing more than a series of 'if's. -- Scott Amspoker Basis International, Albuquerque, NM (505) 345-5232 unmvax.cs.unm.edu!bbx!bbxsda!scott
Technical Details
Message-ID:
<962@bbxsda.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!uunet!ogicse!unmvax!bbx!bbxsda!scottReferences:
<26842@pasteur.Berkeley.EDU> <26857@pasteur.Berkeley.EDU> <56515@microsoft.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!uunet!ogicse!unmvax!bbx!bbxsda!scott From: scott@bbxsda.UUCP (Scott Amspoker) Newsgroups: comp.std.c++ Subject: Re: case() Keywords: case statement Message-ID: <962@bbxsda.UUCP> Date: 13 Aug 90 20:26:17 GMT References: <26842@pasteur.Berkeley.EDU> <26857@pasteur.Berkeley.EDU> <56515@microsoft.UUCP> Reply-To: scott@bbxsda.UUCP (Scott Amspoker) Organization: Basis International, Albuquerque, NM Lines: 38