The extern
keyword provides, by default (whitout an initializer for instance), a declaration of the variable. You need to define your variable. To have an internal linkage:
#include <stdio.h>
#include <stdlib.h>
static int i;
int main(int number, char arg[])
{
extern int i;
i = 5;
printf("%d",i);
return 0;
}
And an external linkage:
#include <stdio.h>
#include <stdlib.h>
int i;
int main(int number, char arg[])
{
extern int i;
i = 5;
printf("%d",i);
return 0;
}
See also here.
C11 (n1570), ยง 6.2.2 Linkages of identifiers
For an identifier declared with the storage-class specifier extern in
a scope in which a prior declaration of that identifier is visible)
if the prior declaration specifies internal or external linkage, the
linkage of the identifier at the later declaration is the same as the
linkage specified at the prior declaration. If no prior declaration is
visible, or if the prior declaration specifies no linkage, then the
identifier has external linkage.