Static functions in C
2005年9月26日
The static storage class specifier for functions:
In the declaration of a function, if you use static, such as:
static void insert_string(char *dest, const char *src);
Then the linker will search only in this file for the function insert_string.
However, if you do not use static in the definition of a function, such as:
void insert_string(char *dest, const char *src)
{
…
}
Then other c files can invoke this insert_string function through declaring it.
If you use static in the definition but not in the declaration, then the linker may link the function to another function with the same name in another file.
If you use static both in the definition and in the declaration, then this ensures that the function is local in the file.