【发布时间】:2020-08-23 15:29:51
【问题描述】:
以下场景有什么区别?
// 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) 都不会放在头文件中?
【问题讨论】:
-
在第一个例子中,即使你没有在
some_file.h中声明some_func,它仍然可以被其他文件使用extern int some_func(int);访问(extern是可选的),在第二个例子中一个some_func不可访问。
标签: c static header-files