相关疑难解决方法(0)

函数声明中的静态关键字在函数定义中可能会丢失吗?

我希望有一个静态函数,我在定义之前在我的.c文件中声明:

//file a.c version 1
static int foo();
...
static int foo()
{
...
}
Run Code Online (Sandbox Code Playgroud)

但是,似乎我可以将static关键字从函数定义中删除,并且我没有得到编译器警告......例如

//file a.c version 2
static int foo();
...
int foo()
{
...
}
Run Code Online (Sandbox Code Playgroud)

假设这两种形式完全相同,我是否正确?
如果是这样,为什么允许这种差异,我应该使用哪种形式?

c c++ static declaration function

11
推荐指数
1
解决办法
7321
查看次数

标签 统计

c ×1

c++ ×1

declaration ×1

function ×1

static ×1