Initialization of automatics within loops

Bruce Blodgett blodgett at apollo.HP.COM
Thu Feb 7 02:57:00 AEST 1991


In article <2293 at inews.intel.com> bhoughto at hopi.intel.com (Blair P. Houghton) writes:
> Note that in:
> 
> 	/* just a block to scope-limit foo and bar */
> 	{
> 	    int foo = 3;
> mickle:
> 	    int bar = 0111;
> 
> 	    foo *= bar;
> 	}
> 
> `mickle:' labels `foo *= bar;', which is a statement,
> rather than `int bar = 0111;', which is a declaration, not
> a statement.  So, despite the fact that `int bar = 0111;'
> appears after `mickle:', it is guaranteed that neither
> initialization is performed.

Section 3.6.1 (Labeled Statements) provides relevant syntax:
labeled-statement:
        identifier : statement

As does Section 3.6.2 (Compound Statement, or Block):
compound-statement:
        { opt-declaration-list opt-statement-list }

Your declarations of foo and bar make up the optional
declaration-list.  foo *= bar; makes up the optional statement-list.
The label mickle: precedes a declaration, not a statement.  This is
not syntactically legal.  There is not a question of whether to assign
0111 to bar "if the block is entered by a jump to a labeled
statement", because you have not provided a legal code fragment.
Bruce Blodgett
blodgett at apollo.hp.com
(508) 256-0176 x4037



More information about the Comp.std.c mailing list