On Monday, January 23, 2012 19:48:02 Timon Gehr wrote:
> On 01/23/2012 07:06 PM, bearophile wrote:
> > Ellery Newcomer:
> >> void main(){
> >> 
> >> for ({int x=0; short y=0;} x< 10; x++, y++){
> >> }
> >> 
> >> }
> > 
> > I don't understand, is that a compiler bug?
> > Aren't x and y in a sub-scope that ends before you use x and y?
> > 
> > Bye,
> > bearophile
> 
> It is not a bug.
> 
> ForStatement:
> for (Initialize Testopt ; Incrementopt) ScopeStatement
> Initialize:
> ;
> NoScopeNonEmptyStatement
> 
> Initialize is NoScope.

That's a pretty cool feature actually, since it gives you much more flexibility 
with regards to the types of the variables that you declare in the beginning 
of the for loop (or other things that you might want to do to the variables 
prior to running the loop. My only concern with it would be programmers not 
understanding it, because they're not used to it. I may start using.

- Jonathan M Davis

Reply via email to