for loop initial declarations are only allowed in c99 or c11 mode

2

How do I resolve the following error?

  

[Error] 'for' loop initial declarations are only allowed in C99 or C11 mode

(I use the C compiler: Dev ++ ).

    
asked by ezz 27.05.2017 в 23:45
source

1 answer

6

Starting with the C99 standard you can initialize a countable variable inside the for loop for easy reading and delimit its scope, but if the compatibility with this standard is not activated, this functionality can not be used.

So a loop in which the variable is defined and used in the same for :

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

You must change it by a previous definition and later use of the variable in for :

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

Either we will have to activate the compatibility in the compiler using the following modifier the configuration of additional parameters (if it is gcc / MinGW GCC ) in "Tools" > "Compiler Options" > "Add the following commands when calling the compiler":

-std=c99
    
answered by 27.05.2017 в 23:52