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



On Thu, 2006-11-02 at 21:42 -0800, Pedro Pinto wrote:
When compiling my program i got this error:

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

This means that you did

for (int i = 0; i < n; i++)
....

Where you declared the variable i after you executed some
statements. The mixing of declarations and code is illegal
in C90 (the "old" standard), but is legal in C99 (the new
standard).

--
Andrew Poelstra <http://www.wpsoftware.net>
For email, use 'apoelstra' at the above site.
"You're only smart on the outside." -anon.

.



Relevant Pages

  • Re: "Sorting" assignment
    ...     If clause-1 is a declaration, the scope of any variables it declares ... in that direction lies COBOL. ... >I don't declare anything inside of a loop is why. ...
    (comp.programming)
  • Re: About String
    ... Ada, where declarations are just as executable as statements. ... I think it does make sense because it clearly defines the scope ... anywhere outside the declaration part. ... for I in A'Range loop ...
    (comp.lang.ada)
  • Re: Error: for loop initial declaration used outside c99 mode
    ... 'for' loop initial declaration used outside c99 mode ... so may be accepted if you are compiling C with a C++ compiler: ... C99 mode, and use that mode. ...
    (comp.lang.c)
  • Re: Newbies question
    ... for I in Elements'Range loop ... I ruled out the declaration of a local array within the block statement Copy_List, because I thought that the compiler would mandate a return statement to be at the top level of the function's body, which I wouldn't be able to do, since the declared array would be local to the block statement. ...
    (comp.lang.ada)
  • Re: static or not static? That is the question!
    ... anything else but a normal declaration that can accept ANY ... This loop would be run only ONCE in the program's lifetime. ... What is strange is to FORBID it, ... I can't imagine wanting to declare a static object in a for statement. ...
    (comp.std.c)