Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!lll-winken!ncis.tis.llnl.gov!helios.ee.lbl.gov!pasteur!ICSI.Berkeley.EDU!krste From: krste@ICSI.Berkeley.EDU ( Krste Asanovic) Newsgroups: comp.std.c++ Subject: case() Keywords: case statement Message-ID: <26842@pasteur.Berkeley.EDU> Date: 8 Aug 90 08:59:17 GMT Sender: news@pasteur.Berkeley.EDU Reply-To: krste@ICSI.Berkeley.EDU ( Krste Asanovic) Organization: International Computer Science Institute, Berkeley, CA Lines: 22 X-Local-Date: 8 Aug 90 01:59:17 PDT The C/C++ switch statement is very limited as it only allows integer expressions. I'd like to suggest a more general case statement. The syntax would be, case (exp) { case val1 : s1; case val2 : s2; default : sOther; } This uses the already reserved keyword case, followed by a parenthesised expression, to introduce the construct. The standard switch case and default labels would be used as before. The limitation that case label expressions are compile-time constants would be removed (although optimizing compilers could check for this case). The limitation that case labels be unique would be removed (can't check this at run time), but the order in which case expressions were tested would be undefined. Comparisions would use the appropriate == operator, in the above example the tests would be if (exp.operator==(val1)) ..s1... \ in undefined order. if (exp.operator==(val2)) ..s2... /