-
static修饰的函数为本源文件专属函数,不能被外部函数调用。
-
那么我们如何用外部函数调用呢?
A.c文件声明一个函数:
static u8 test ();
u8 (*pfun)(void);
定义:
static u8 test()
{
printf("This is a atatic function!");
return 1;
}
void init ()
{
pfun=u8;
}
B.c文件中有一个函数:
...
void test2()
{
u8 temp;
temp=pfun();//就可以调用了
}
void main()
{
init();
test2();
}
内部(静态)函数虽然不可以被外部函数直接调用,但是可以通过函数指针间接调用。