the function f in 2.o have global scope, and 1.c if he wanted he could use it. but in 1.o have unique definition of f. the linker agree to accept it though How is there no conflict here and which definition does he choose and why ? Doesn't the function f in file 2.c have to be static as well ?
1.c
static void f() {
}
gcc -c 1.c
2.c
void f() {
}
gcc -c 1.c
gcc 1.o 2.o -myprog
There is no problem here. Function
fin 2.c is globally visible. Functionfin 1.c is only visible inside that translation unit, i.e. only visible to code inside 1.c. The functionfin 2.c is not known to any part of 1.c because you didn't declare it as an extern function, so any code in 1.c that references (or calls)fwill use thefdefined in 1.c.