我发现在C语言中有两种使用静态函数的方法。
第一种方法是:
afile.h
static void afunc(void); // leaving this out gives errors
afile.c
void afunc(void)
{
puts("a");
}
void callafunc(void)
{
afunc();
}
main.c
void afunc(void)
{
puts("b");
}
int main(void)
{
afunc(); // prints b
callafunc(); // prints a
}
另一种方法是:
afile.h
// declare nothing w.r.t. static functions
afile.c
static void afunc(void)
{
...
}
main.c
static void afunc(void)
{
...
}
这两种使用静态函数的方式哪种是正确的?
static
影响链接,而不是作用域。 - Eric Postpischil