tags:

views:

58

answers:

3

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

AFAICT, 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.

+2  A: 

Try -Wno-traditional.

But better, add declarations for your static functions:

static void foo (void);

// ... somewhere in code
    foo ();

static void foo ()
{
    // do sth
}
el.pescado
`-Wno-traditional` didn't work.
Alsciende
+3  A: 

While gcc 3.2.3 was more forgiving of the issue, gcc 4.1.2 is highlighting a potentially serious issue for the linking of your program later. Rather then trying to suppress the error you should make the forward declaration match the function declaration.

If you intended for the function to be globally available (as per the forward declaration) then don't subsequently declare it as static. Likewise if it's indented to be locally scoped then make the forward declaration static to match.

bjg
+1  A: 

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.

hlovdal
Indeed the code doesn't prototype the function, so gcc assumes an implicit static declaration. The right answer is that there's no option to turn this error off.
Alsciende
You can turn implicit declarations into errors with `-Werror-implicit-function-declaration` (under gcc 3.4, anyway; not sure about later versions).
detly