I was trying out programs based on extern and as i understand, this is helpful when accessing variables across multiple files having only one definition.
But i tried a simple program as below without "extern" and thing seem to work when i expected it would fail during linking process
Code:file5.c 1 #include <stdio.h> 2 #include "var.h" 3 4 int main() { 5 6 printf("\n File5.c a = %d", a); 7 test(); 8 return 0; 9 }Code:file6.c 1 #include <stdio.h> 2 #include "var.h" 3 4 int test() { 5 printf("\n File6.c a = %d",a); 6 }As i have included "var.h" in all header files without extern, "int a" would be included in both the .c file and during linking, compiler should have thrown a warning or error message but it compiles file without any issue. Shouldn't var.h have the following "extern int a"?Code:var.h int a;