This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/31121] New: for loop variable declartion gives error message
- From: "frederik dot hertzum at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 10 Mar 2007 13:59:03 -0000
- Subject: [Bug c/31121] New: for loop variable declartion gives error message
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
gcc (not g++) seems to treat for loops rather oddly. Sometimes (not all the
time -- appears to be somewhat random), if a variable is declared in the header
of the for loop it complains with the following message:
?for? loop initial declaration used outside C99 mode
The following program demonstrates the problem:
#include <stdio.h>
int main()
{
#ifndef WORKAROUND
// this part demonstates the bug.
for (int i = 0; i < 10; i++)
#else
// this is the workaround that makes for loops work.
int i = 0;
for (;i < 10; i++)
#endif
printf ("%d\n", i);
return 0;
}
If compiled with WORKAROUND declared it demonstartes a possible workaround.
--
Summary: for loop variable declartion gives error message
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: frederik dot hertzum at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31121