Declarations in switches, errors

Conor P. Cahill cpcahil at virtech.UUCP
Fri Sep 29 10:30:59 AEST 1989


In article <11173 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
> In article <1202 at virtech.UUCP>, cpcahil at virtech.UUCP (Conor P. Cahill) writes:
> > If this is the standard, I think it is broken.  If the compiler allows 
> > a variable declaration, it should allow an initialization.
> If I recall correctly (my copy of the Standard is not at hand), you can
> specify the initializer but of course it won't be executed.  Consider
> the following analogous case (which does NOT involve "switch") to see why:
> 
> 	goto label;
> 	{
> 		int i = 4;
> 		foo();
> 	label:	bar();
> 		baz();
> 	}



I still don't agree with this.  One does not "conceptualize" the initialization
as an execution.  Since the code used to allocate the automatic variable on 
the stack is executed, the code used to initialize the variable should be
executed.

In addition the behavior is different if the declaration is "static int...".
In that case the initialization does take place.  What it the justification
for the different behavior?  



-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.std.c mailing list