When I try:
#include <stdio.h>
static int c1 = 10;
int main(){
{
extern int c1; //c1 here still has internal linkage
printf("%d",c1);
}
return 0;
}
Nothing goes wrong. But when I try to modify it a little bit like this:
#include <stdio.h>
static int c1 = 10;
int main(){
int c1 = 20; //This is where I modified.
c1++;
{
extern int c1;
printf("%d",c1);
}
return 0;
}
And suddenly, there's an error coming out. It says "variable previously declared 'static' redeclared 'extern'". Why?
Verbatim error message:
prog.c: In function ‘main’:
prog.c:11:20: error: variable previously declared ‘static’ redeclared ‘extern’
extern int c1;