I'm trying to solve the 3n+1 problem and I have a for
loop that looks like this:
for(int i = low; i <= high; ++i)
{
res = runalg(i);
if (res > highestres)
{
highestres = res;
}
}
Unfortunately I'm getting this error when I try to compile with GCC:
3np1.c:15: error: 'for' loop initial declaration used outside C99 mode
I don't know what C99 mode is. Any ideas?
I've gotten this error too.
is not valid in the C89/C90 standard. As OysterD says, you need to do:
Your original code is allowed in C99 and later standards of the C language.
To switch to C99 mode in CodeBlocks, follow the next steps:
Click Project/Build options, then in tab Compiler Settings choose subtab Other options, and place
-std=c99
in the text area, and click Ok.This will turn C99 mode on for your Compiler.
I hope this will help someone!
Just compile in C++ mode. You don't NEED to use classes to use C++. I basically use C++ as a "nicer C" :)
I almost never use classes and never use method overiding.
For Qt-creator: just add next lines to *.pro file...
I had the same problem and it works you just have to declare the
i
outside of the loop:Jihene Stambouli answered OP question most directly... Question was; why does
produce the error;
for which the answer is
should be