Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!shadooby!samsung!uunet!littlei!guardian!peter From: peter@guardian.UUCP (peter) Newsgroups: comp.std.c Subject: Re: Scope of switch statements Message-ID: <301@guardian.UUCP> Date: 14 Nov 89 18:27:20 GMT References: <15743@bloom-beacon.MIT.EDU> <1989Nov9.200639.8868@utzoo.uucp> Reply-To: peter@langlab1.hf.intel.com (Peter Plamondon) Organization: Intel Development Tools Operation, Hillsboro OR Lines: 40 In article <1989Nov9.200639.8868@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes: |In article <15743@bloom-beacon.MIT.EDU> tada@athena.mit.edu (Michael J Zehr) |writes: |>There was a recent article in comp.lang.c on obfuscated use of switches |>and labels mixed together which i decided to try to compile using DEC's |>VAX C (VMS) compiler: |>#include |>main() { |> int i, j=1, k=1; |> for(i=0; i<=2; ++i) |> switch(i) { |> case 0: for(; ++k % 3; ++j) { |> case 1: printf(" j = %d,", j); |> case 2: printf(" k = %d,", k); |> } |> } |>} |> |>(i've reduced the code to just the section i have a question concerning) |> |>on the '1' and '2' case lines, the compiler gives an error "case labels |>are valid only in "switch" statements." |> |>is this obfuscated code not ANSI or is the compiler broken? | |It is legal, although ugly, ANSI C. Also legal (but ugly) traditional C. |Dennis Ritchie himself has officially blessed this disgusting construct, |and indeed it has one or two legitimate uses. (Michael Zehr's original posting added for clarity) I've stared at this and can't make sense of it. Could someone provide me with enlightenment? ------------------------------------------------------------------------------- Peter Plamondon, Intel Corp, 5200 NE Elam Young Pkwy, Hillsboro, OR 97124-6497 Internet: peter@langlab1.hf.intel.com +1 503-696-5219 UUNET : uunet!intelhf!langlab1!peter "I speak for myself, as best I can." UUCP : tektronix!psueea!foobar!langlab1.hf.intel.com!peter -------------------------------------------------------------------------------