Declaring a variable as static in one file and do a extern declaration in another file - i thought this will give an error while linking as the extern variable will not be seen in any object, as the one which declared in other file was with qualifier static. But somehow the linker(renesas) didn't show any error and created executable.
If the above usecase was correct, what will happen if 2 variables be declared as static in 2 different files and another in another file with extern declaration? In this case 2 different memories will be created in 2 different objects, but which one of the variable will be linked for other variable was declared as extern in another file(as both the variable name are same)??
file1.c
static int test_var;
fn1()
{
test_var = 1;
}
file2.c
static int test_var;
fn2()
{
test_var = 2;
}
file3.c
extern int test_var;
fn3()
{
int x;
x = test_var;
}