How to solve static declaration follows non-static declaration in GCC C code?

I'm trying to compile the same C file on two different machines with different versions of cc.

gcc version 3.2.3 says warning: 'foo' was declared implicitly 'extern' and later 'static'

gcc version 4.1.2 says error: static declaration of 'foo' follows non-static declaration

Both have the same CFLAGS. I'd like to make gcc 4.1.2 behave like gcc 3.2.3, that is, find an option that would turn this error into a mere warning.


Solution 1:

From what the error message complains about, it sounds like you should rather try to fix the source code. The compiler complains about difference in declaration, similar to for instance

void foo(int i);
...
void foo(double d) {
    ...
}

and this is not valid C code, hence the compiler complains.

Maybe your problem is that there is no prototype available when the function is used the first time and the compiler implicitly creates one that will not be static. If so the solution is to add a prototype somewhere before it is first used.

Solution 2:

I have had this issue in a case where the static function was called before it was declared. Moving the function declaration to anywhere above the call solved my problem.