I know about the static keyword in C before a function declaration to only allow the file it is declared at to use the function (the compilation unit, to be more precise). I've done some research and I have found already answered questions regarding including them in headers, and what it does in detail, but I have one that I think is missing:
Does the static keyword add anything to a program, when there's no other declaration of a function but the one followed by its definition ?
e.g. :
main.c
#include "foo.h"
int main () {
foo();
return 0;
}
foo.c
void foo2() {
return ;
}
void foo() {
return foo2();
}
foo.h
void foo();
What would be the difference if foo2() was declared as static void ?
staticthe compiler might not be able to prove thatfoo2()isn't externally visible (via some header), so would have to export the symbol. This would increase the size of the resultant binary.foo2asstaticthen it would have internal linkage and be "private" to the translation unit it's defined in.staticwould be a good idea. But also heed the advice of @DevSolar about "not fixing what isn't broken".static.