Re: Error: 'for' loop initial declaration used outside c99 mode



"Pedro Pinto" <kubic62@xxxxxxxxx> writes:
When compiling my program i got this error:

Error: 'for' loop initial declaration used outside c99 mode


What is it and how can i solve it?

It's an error message about some code that you failed to show us. In
general, you can't expect us to know what the problem is unless you
show us the actual code as well as the error message.

In this case, you've lucked out. You probably have something like this:

...
for (int i = 0; i < N; i ++) {
...
}
...

which declares the loop variable as part of the for loop itself. This
feature was added to the language with the C99 standard; it's not
supported in C90.

You can either use C99 mode (but beware: gcc doesn't fully support
C99; see <http://gcc.gnu.org/c99status.html>), or you can re-write
the code to be compatible with C90:

...
int i;
...
for (i = 0; i < N; i ++) {
...
}
...

which is legal C99 as well.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Re: Newbie pointers and reversing question
    ... If you are using C99 you can use ... char tmp; ... int main ... If i remove the while loop it prints the correct value 7!How does the while loop affect the value of printf?Seems strange to me! ...
    (comp.lang.c)
  • Re: "Sorting" assignment
    ... Yes, this is also legal C (traditional, C90, and C99) as written. ... the first substatement is executed if the expression ... In the else form, the second substatement is ... When you jump into a loop, on the other hand, the loop test is executed ...
    (comp.programming)
  • Re: switch/continue
    ... Christopher Benson-Manica writes: ... > The indicated continue statement will apply to the for loop, ... As C99 says, "A continue statement causes a jump to the ... that a switch statement is not an iteration statement. ...
    (comp.lang.c)
  • Re: help with string splitting
    ... this code confuses me ... Code_Index is a variable declared as part of for loop. ... C99 can do that as ... Ada programming at: http://ada.krischik.com ...
    (comp.lang.ada)
  • Re: What are C89 and C99 ?
    ... None of the popular implementations is C99 conforming, ... really C99 mode, but as close to C99 as the compiler can currently get). ... Dan Pop ...
    (comp.lang.c)