The thing is, you can have any number of extern declarations of a variable before you declare the variable itself. This compiles and runs with no worries:
Code:
#include <stdio.h>
extern int x;
extern int x;
extern int x;
int x;
int main() {
x = 3;
printf("%i\n", x);
return 0;
}
So you can have a header file like this
Code:
/* header.h */
extern int x;
because it works in code that doesn't declare the variable
Code:
#include <stdio.h>
#include "header.h"
void print(void) {
printf("%i\n", x);
}
as well as in code that does:
Code:
#include "header.h"
int x;
int main() {
x = 3;
print();
return 0;
}