Why declaration by extern
doesn't work with static
functions?
Because extern
indicates external linkage while static
indicates internal linkage. Obviously, You cannot have both on same function.
In simple words, when you use static
on the function you tell the compiler please limit the scope of this function only to this translation unit and do not allow anyone to access this from another translation unit.
while function declarations are extern
by default, when you specify extern
explicitly you tell the compiler, Please allow everyone from other translation units to access this function.
Well obviously the compiler cannot do both.
So make a choice, whether you want the function to be visible only in the translation unit or not.
If former make it static
and forget extern
. If latter just drop the static
.
Good Read:
What is external linkage and internal linkage?
Though above Q is for C++, most of what is discussed applies to C as well.