This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/21837] C++/C99 standard violation in for loop
- From: "joseph at codesourcery dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 31 May 2005 11:48:33 -0000
- Subject: [Bug c++/21837] C++/C99 standard violation in for loop
- References: <20050531104619.21837.ahelm@gmx.net>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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