suspicious error 'static declaration follows non-static declaration'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux