Scope of switch statements

peter peter at guardian.UUCP
Wed Nov 15 05:27:20 AEST 1989


In article <1989Nov9.200639.8868 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer)
writes:
|In article <15743 at bloom-beacon.MIT.EDU> tada at 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 <stdio.h>
|>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 at 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    
-------------------------------------------------------------------------------



More information about the Comp.std.c mailing list