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/31121] New: for loop variable declartion gives error message


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


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