Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!hsi!mfci!karzes From: karzes@mfci.UUCP (Tom Karzes) Newsgroups: comp.std.c Subject: Re: Declarations in switches, errors Message-ID: <1061@m3.mfci.UUCP> Date: 4 Oct 89 17:37:01 GMT References: <561@crdos1.crd.ge.COM> <11158@smoke.BRL.MIL> <637@crdos1.crd.ge.COM> <1989Sep30.052000.13719@utzoo.uucp> <30540@news.Think.COM> <1989Oct3.184849.20106@sq.sq.com> Sender: karzes@mfci.UUCP Reply-To: karzes@mfci.UUCP (Tom Karzes) Organization: Multiflow Computer Inc., Branford Ct. 06405 Lines: 38 In article <1989Oct3.184849.20106@sq.sq.com> msb@sq.com (Mark Brader) writes: >Actually, there *is* a way to "normally enter" the switch body. >Instead of entering the body by a jump from the switch header, you >put a label on the body itself and jump to that! >... >Only slightly less bizarre is to put one of the case labels ON the >switch body rather than IN it -- 3.6.4.2 allows this and the compilers >we have here support it -- whereupon you get initialization IF it is >the first case that is chosen. Note that although normal switch statement usage almost always involves a compound statement with all case labels at the top level within the compound statement, the syntax actually allows any statement. For example, the following: switch (x) case 5: case 9: foo(); if equivalent to: if ((t = x) == 5 || t == 9) foo(); where t is some temporary to avoid evaluating x more than once. Similarly, one might have: switch (x) case 2: if (y) default: foo(); else case 7: while (bar(z)) { case 12: baz(); case 13: z++; } Again, I'm not advocating any of this, I'm merely pointing out that it's within the definition of the language.