【发布时间】:2021-06-21 03:10:09
【问题描述】:
是否可以使用 static 关键字编写函数的 forward declaration 但稍后在不使用 static 关键字的文件中实现它?
例如:
#include <stdio.h> /* printf */
static void func();
int main()
{
func();
return(0);
}
void func()
{
printf("Hello World");
}
它编译和运行没有任何错误,但 func 是否是 static 函数?为什么?
【问题讨论】:
-
它是静态的,因为你已经这样声明了。
-
这样写可以吗?用特定关键字声明函数,然后在没有它的情况下实现它?被接受了吗?
-
前向声明应该是
static void func(void);,因为函数没有参数。
标签: c static declaration implementation forward-declaration