2

I try to redefine a variable and initialize them with zero. Not unexpectedly, the compliation terminates with error:redefinition of a.

#include <stdio.h>
static int a = 0;
static int a = 0;
int main()
{
    return 0;
}

To my surprise, after removing the initialization, the program is successfully compiled.

#include <stdio.h>
static int a ;
static int a ;
int main()
{
    return 0;
}

What's more, I try to initialize only one of the two variables, and the compliation is successful either.

#include <stdio.h>
static int a ;
static int a = 0;
int main()
{
    return 0;
}

I know the difference of "strong symbol" and "weak symbol" in ELF object files. But according to CSAPP, these concepts are related with global variables, not static ones. So I think it couldn't answer my questions here.

The compiler is gcc 8.1.0 built by MinGW-W64 project in Windows 10.

Thanks in advance.

SToPire
  • 21
  • 1

0 Answers0