更新时间:2022-05-12 01:13:57
考虑两个功能:
extern int extern_sqr(int i) { return i * i; }
static int static_dbl(int i) { return i * 2; }
那么谁参照 extern_sqr
人会指的是功能。这是反对静态
联动,其中从翻译单位(大概它定义的文件)中的人才能访问功能 static_dbl
。
Then people who refer to extern_sqr
will be referring to that function. This is opposed to static
linkage, where only people from within the "translation unit" (roughly the file it's defined) can access the function static_dbl
.
原来,该的extern
默认情况下,在C暗示。所以,你会得到相同的行为,如果你写:
It turns out, that the extern
is implied by default in c. So, you would get the same behavior, if you wrote:
int extern_sqr(int i) { return i * i; }
较新的C类标准仍然需要一个函数声明,因此,通常在头文件中的某个地方,你会遇到:
Newer C standards still require a "function declaration" so, usually in a header file somewhere, you'll encounter:
int extern_sqr(int i); // Note: 'i' is optional
它说的地方,在其他一些翻译单元,我有一个调用的函数 extern_sqr
。
同样的逻辑也适用于变量。
The same logic applies to variables.