Thoroughly confused. I'm frustrated because I think it's important to know precisely how scope and linkage work, but I've been seeing conflicting info about extern and my compiler/linker is contradicting what I've read.
----------main.c--------------
int int1;
void main()
{ int1=6;
printf("\nMain - int1 = %4d", int1);
blippy();
printf("\nMain - int1 = %4d", int1);
return;
}
-------------second.c-------------
int int1;
void blippy()
{ printf("\nSecond - int1 = %4d", int1);
int1++;
return ;
}
Output is:
Main - int1 = 6
Second - int1 = 6
Main - int1 = 7
as if both instances of int1 pointed to one variable with external linkage. I would have expected the compiler to either throw a multiple definition error or treat them as static. I'm using Codeblocks, and I don't know if it's doing anything presumptous behind the scenes.