1.h
extern int a;
1.c
#include <stdio.h>
#include "1.h"
int main(){
printf("%d\n", a);
return 0;
}
2.c
#include "1.h"
int a = 6;
This compiles and runs just fine (gcc 1.c 2.c) if you remove extern from 1.h and prints 6.
I know that removing it might cause a to be defined in every translation unit (object file), but what is the problem? doesn't the linker just git rid of it when linking since it compiles with no errors?