Below are two separate codes written in two separate files Test1.c and Test2.c. I do not use the keyword externin any file.
#include <stdio.h>
int a = 1;
int main()
{
printf("test1 - a val = %d\n",a);
fn();
printf("After Return : %d",a);
}
#include <stdio.h>
int a;
int fn()
{
printf("test2 - a val = %d\n",a);
a++;
}
I compiled this code with gcc:
gcc Test1.c Test2.c
It generates the following output:
test1 - a val = 1
test2 - a val = 1
I tried printing the address of the variable ain both codes. The address is also the same.
Now I have the following questions:
- Can it
gccautomatically compile and link, even if externnot in use? Here, apparently, gccinternally does this when compiling these two files together. - Does this behavior with / without a
externkeyword depend on the compiler?