home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16536 < prev    next >
Encoding:
Text File  |  1992-11-18  |  2.3 KB  |  51 lines

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