以下方案之间有什么区别?
// some_file.c
#include "some_file.h" // doesn't declare some_func
int some_func(int i) {
return i * 5;
}
// ...
和
// some_file.c
#include "some_file.h" // doesn't declare some_func
static int some_func(int i) {
return i * 5;
}
// ...
如果static
对函数的所有操作都限制了它们对文件的可访问性,那么这两种情况都意味着some_func(int i)
只能从头文件访问,some_file.c
因为这两种情况都没有some_func(int i)
放在头文件中?
区别在于,使用非静态函数时,仍可以在其他转换单元中声明它(头文件与此无关)并被调用。静态功能根本无法从任何其他翻译单元中看到。
在另一个函数中声明一个函数甚至是合法的:
foo.c:
void foo()
{
void bar();
bar();
}
bar.c:
void bar()
{ ... }
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句