ISO C90 forbids mixed declarations and code in C

user707549 picture user707549 · Nov 8, 2012 · Viewed 133.7k times · Source

I declared a variable in this way:

int i = 0;

I get the warning:

ISO C90 forbids mixed declarations and code

How can I fix it?

Answer

Johan Kotlinski picture Johan Kotlinski · Nov 8, 2012

I think you should move the variable declaration to top of block. I.e.

{
    foo();
    int i = 0;
    bar();
}

to

{
    int i = 0;
    foo();
    bar();
}