This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
suspicious error 'static declaration follows non-static declaration'
- From: Andrew Makhorin <mao at gnu dot org>
- To: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 16 Feb 2018 17:41:21 +0300
- Subject: suspicious error 'static declaration follows non-static declaration'
- Authentication-results: sourceware.org; auth=none
Hello,
On compiling the following code with gcc (Debian 4.7.2-5) 4.7.2:
int foo(int x, int y)
{
extern int bar();
return bar(x, y);
}
static int bar(int x, int y)
{
return x + y;
}
I get the following error:
mao@corvax:~/Desktop$ gcc -c test.c
test.c:7:15: error: static declaration of 'bar' follows non-static
declaration
test.c:3:21: note: previous declaration of 'bar' was here
However, the Standard says [6.1.2.2 Linkages of identifiers]:
If the declaration of an identifier for an object or a function
contains the storage-class specifier extern, the identifier has the
same linkage as any visible declaration of the identifier with file
scope.
There is no other way to declare 'bar' as static in block scope,
because it is a function, so this error confuses me. Could anyone
explain this? Should it be a warning rather than error? I'd like to note
that my code is compiled successfully with older versions of gcc and
with many other C compilers.
Thanks,
Andrew Makhorin