本文介绍了用C静态函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是做一个静态函数在C点?
What is the point of making a function static in C?
推荐答案
制作功能静态
从其他翻译单元隐藏它,这有助于提供的
Making a function static
hides it from other translation units, which helps provide encapsulation.
helper_file.c
int f1(int); /* prototype */
static int f2(int); /* prototype */
int f1(int foo) {
return f2(foo); /* ok, f2 is in the same translation unit */
/* (basically same .c file) as f1 */
}
int f2(int foo) {
return 42 + foo;
}
的main.c
int f1(int); /* prototype */
int f2(int); /* prototype */
int main(void) {
f1(10); /* ok, f1 is visible to the linker */
f2(12); /* nope, f2 is not visible to the linker */
return 0;
}
这篇关于用C静态函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!