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 ++ ).
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 ++ ).
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