在函数声明Static关键字可以在函数定义会丢失? [英] Static keyword in function declaration can be missing in function definition?
问题描述
我想有我在.c文件中定义之前声明静态函数:
I want to have a static function which I declare in my .c file before defining it:
//file a.c version 1
static int foo();
...
static int foo()
{
...
}
不过,似乎我可以离开静态
关键字出来的函数定义和我没有得到任何编译器警告......例如
However, it seems that I can leave the static
keyword out of the function definition and I get no compiler warnings... e.g.
//file a.c version 2
static int foo();
...
int foo()
{
...
}
我在承担这两种形式是完全一样的正确吗?结果
如果是这样,为什么这种差异允许的,我应该使用哪种形式?
Am I correct in assuming these two forms are exactly the same?
If so, why is this discrepancy allowed and which form should I use?
推荐答案
是7.1.1 / 6
Yes 7.1.1/6
没有的存储类说明符在命名空间范围内声明的名称的有外部链接,除非它有因为previous声明的内部连接,并提供其未声明常量
。
A name declared in a namespace scope without a storage-class-specifier has external linkage unless it has internal linkage because of a previous declaration and provided it is not declared
const
.
另见的例子7.1.1 / 7
See also the examples of 7.1.1/7
这篇关于在函数声明Static关键字可以在函数定义会丢失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!