Path: utzoo!attcan!uunet!cs.utexas.edu!mailrus!ames!uhccux!munnari.oz.au!lawley
From: lawley@cs.mu.OZ.AU (michael lawley)
Newsgroups: comp.std.c
Subject: Re: Declarations in switches, errors
Message-ID: 
Date: 2 Oct 89 03:14:34 GMT
References: <561@crdos1.crd.ge.COM> <11158@smoke.BRL.MIL>
	<637@crdos1.crd.ge.COM> <19907@mimsy.UUCP> <2260@munnari.oz.au>
Sender: news@cs.mu.oz.au
Reply-To: lawley@cs.mu.OZ.AU
Distribution: comp
Organization: Computer Science Dept., University of Melbourne, Australia.
Lines: 45
In-reply-to: ok@cs.mu.oz.au's message of 1 Oct 89 14:32:00 GMT


On 1 Oct 89 14:32:00 GMT,
ok@cs.mu.oz.au (Richard O'Keefe) said:

> In article <19907@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes:
>> Even a compiler that is only 1/3 decent% will warn about unreachable
>> initialisers.

> I tried the following program (laid out to fit in two lines):
> 	main(argc) int argc; { switch (argc) { int i = 1; double x = 2.0;
>         case 1: case 2: exit(i); default: exit(!!x); }}
> On a Sun-3/50 running SunOS 4.0.something
> 	cc:	"line 1: warning: statement not reached"
> 	CC:	"warning:  statement not reached: case label missing"
> 	lint:	"(1): warning: statement not reached"
> 	gcc:	/* silence */
> 	gcc -W:	/* silence */

I just ran the same code through "gcc -Wall -O".  The -O causes gcc to do
dataflow analysis etc. which it would otherwise not do.  Here is the output:

tt.c: In function main:
tt.c:1: warning: return-type defaults to `int'
tt.c:2: warning: implicit declaration of function `exit'
tt.c:1: warning: `i' may be used uninitialized in this function
tt.c:1: warning: `x' may be used uninitialized in this function
tt.c:2: warning: control reaches end of non-void function

Running with just "gcc -W -O" (for those of you who like sloppy code) gives

tt.c: In function main:
tt.c:1: warning: `i' may be used uninitialized in this function
tt.c:1: warning: `x' may be used uninitialized in this function

> I suppose you *could* call this warning about unreachable initialisers,
> but calling them unreachable *statements* seems a little unhelpful.
> CC's message makes sense because C++ *would* allow a case label before
> the declarations (so the initialisers would be done sometimes!).

These would seem to me to be much more useful error messages than the other
compilers produce.

> Do I have permission to call gcc indecent now? 

What about now?