是不必要的,在C函数extern关键字? [英] Is extern keyword for function necessary at all in C?
问题描述
在我看来,即使我指的是功能与出extern声明另一个文件,GCC仍然可以编译单元。所以我想知道extern声明是否是必要的功能,随时随地?我知道你需要为变量的extern。
It appears to me that even if I refer to a function in another file with out extern declaration, gcc can still compile that unit. So I am wondering whether the extern declaration is necessary anywhere for function? I know that you need extern for variables.
推荐答案
这是没有必要的,但我的头preFER它强化了这一功能被定义在其他地方的想法。
It's not necessary, but I prefer it in headers to reinforce the idea that this function is defined somewhere else.
在我看来,这样的:
int func(int i);
是稍后将需要的功能的前向声明,而这
is a forward declaration of a function that will be needed later, while this:
extern int func(int i);
是将这里使用一个函数的声明,但在其他地方定义。
is a declaration of a function that will be used here, but defined elsewhere.
这两条线在功能上是相同的,但是我用的是的extern
关键字记录的差异,并与常规变量的一致性(区别在哪里的是重要,并具有正是意思)。
The two lines are functionally identical, but I use the extern
keyword to document the difference, and for consistency with regular variables (where the difference is important, and has exactly that meaning).
这篇关于是不必要的,在C函数extern关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!