looks like gcc incorrectly processes linkage of identifiers

Jonathan Wakely jwakely.gcc@gmail.com
Sun Oct 5 15:11:41 GMT 2025


On Sun, 5 Oct 2025, 13:49 Andrew Makhorin via Gcc-help, <
gcc-help@gcc.gnu.org> wrote:

> Hi,
>
> I get the following error:
>
> mao@corvax:~/Desktop$ cat test.c
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(void)
> {     double foo = 123.456;
>       printf("%g\n", foo);
>       {  extern int foo(void);
>          printf("%d\n", foo());
>       }
>       return 0;
> }
>
> static int foo(void) { return 789; }
>
> mao@corvax:~/Desktop$ gcc test.c
> test.c:13:12: error: static declaration of ‘foo’ follows non-static
> declaration
>    13 | static int foo(void) { return 789; }
>       |            ^~~
> test.c:7:21: note: previous declaration of ‘foo’ with type ‘int(void)’
>     7 |       {  extern int foo(void);
>       |                     ^~~
> mao@corvax:~/Desktop$ gcc --version
> gcc (Debian 12.2.0-14+deb12u1) 12.2.0
> Copyright (C) 2022 Free Software Foundation, Inc.
>
> However, the Standard (3.1.2.2 Linkage of identifiers) says:
>
>         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.
>
> Could anyone please explain me what's wrong?
>

At the point of the extern declaration, the static one at file scope is not
yet visible.


More information about the Gcc-help mailing list