Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!munnari.oz.au!cs.mu.oz.au!ok
From: ok@cs.mu.oz.au (Richard O'Keefe)
Newsgroups: comp.std.c
Subject: Re: Declarations in switches, errors
Message-ID: <2257@munnari.oz.au>
Date: 30 Sep 89 08:25:04 GMT
References: <561@crdos1.crd.ge.COM> <1989Sep29.022836.12674@twwells.com>
Sender: news@cs.mu.oz.au
Lines: 25

In article <561@crdos1.crd.ge.COM> davidsen@crdos1.UUCP (bill davidsen) writes:
: In the process of looking for a totally diferent problem, I generated
: the following program:
: main() {
:  int i = 2;
:  switch (i) {
:   int j = 4;
:  case 1: j += 4; break;
[much deleted]

C has *always* worked like this.  The body of a switch is a statement
and the switch is a jump.  Here's a really ugly piece of code I wrote
to illustrate this once:
    main(argc)
	{
	    switch (argc)
		if (0) case 1: printf("1\n");
                else if (0) default: printf("not 1\n");
		else printf("impossible\n");
	    exit(0);
	}
"gcc -ansi -pedantic" still likes it!  If you want initialised declarations,
put the switch inside the block instead of the block inside the switch.
A good C compiler ought to print a warning message about initialised
declarations in a switch() body, but that's "quality of implementation".