------- Additional Comments From ahelm at gmx dot net 2005-05-31 17:41 ------- Subject: Re: C++/C99 standard violation in for loop
At 12:48 31/05/2005, joseph at codesourcery dot com wrote: > >------- Additional Comments From joseph at codesourcery dot com 2005-05-31 >11:48 ------- >Subject: Re: New: C++/C99 standard violation in for loop > >On Tue, 31 May 2005, ahelm at gmx dot net wrote: > >> for(int i=2;i<4;i++) >> { >> int j = i; >> int i; >> i = 555; >> printf("%d %d\n", i, j); >> } > >I don't see why you think there's any problem in C99 terms. The for >statement forms a block (6.8.5#5 first sentence); its body forms a block >whose scope is a strict subset of that of the for statement (second >sentence) and the compound statement is itself a block (whether the same >block or a different one from that of the body as body doesn't matter in >this case, but if the body is a labeled compound statement then you'd have >distinct scopes). As these are distinct blocks, they are distinct scopes; >you can declare i in the block which contains the for statement, and in >the declaration part of the for statement, and in the body of the for >statement. I knew I missed something... The end of scope description in the "for" chapter, "end of the loop" sounded rather nebulous to me, that's why I wasn't 100% sure about C99. Thanks for pointing this out. Regards, Tony -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21837