This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/21837] C++/C99 standard violation in for loop


------- 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.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21837


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]