home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!caen!hellgate.utah.edu!fcom.cc.utah.edu!val
- From: val@news.ccutah.edu (Val Kartchner)
- Subject: Re: Proposal - enhancement for switch statement.
- Message-ID: <1992Nov18.235847.27092@fcom.cc.utah.edu>
- Sender: news@fcom.cc.utah.edu
- Organization: University of Utah Computer Center
- X-Newsreader: Tin 1.1 PL3
- References: <1992Nov16.093252.14843@cbfsb.cb.att.com>
- Date: Wed, 18 Nov 92 23:58:47 GMT
- Lines: 38
-
- nh@cbnewsg.cb.att.com (nicholas.hounsome) writes:
- : I find that switch statements tend to be much larger than if-then-else -
- : for some reason people seem less inclined to use subsidiary functions in
- : switches than in if-then-else. I have no idea why this should be so.
- :
- : I find that having break for both loops and switches means that I have
- : to create loop exit variables which I hate - I would much rather write
- : ... if( c == 'q' ) break; than case 'q': quit = TRUE; break;
- :
- : In this day and age we should expect compilers to recogize a sequence
- : of i-then-else which can be implemented as a jump table. The register
- : qualifier is now universaly unnecessary - the switch statement should
- : be as well.
-
- The problems with doing if-else statements instead of switch statements are:
-
- 1) it is easier to see that a switch statement is comparing against a
- single statement.
-
- 2) Compilers don't currently do this kind of optimization. (Though as
- you pointed out, they should.)
-
- However, you do have a point about breaks not exiting loop constructs.
- The simplest way to solve this would be to add loop labels and break <label>.
-
- Rather than adding another keywork (like 'breakc'), you could just add
- another syntax to break to cause automatic breaking after every case.
- This syntax could be of the form of 'switch[c]'. This would not interfere
- with any valid code since the use of the square brackets would have no
- valid meaning in previous versions of the language. ('switch' is always
- a reserved word, so it could never be an array.)
-
- -=:[ VAL ]:=-
- --
- |================== #include <disclaimer.h> ==================///=============|
- | "AMIGA: The computer for the creative mind" (tm) Commodore /// Weber State |
- | "Macintosh: The computer for the rest of us"(tm) Apple \\\/// University |
- |== "I think, therefore I AMiga" -- val@csulx.weber.edu ==\///= Ogden UT USA =|
-