问题描述
// case 1
unsigned int add_two_numbers(unsigned char a, unsigned char b);
//case 2
extern unsigned int add_two_numbers(unsigned char a, unsigned char b);
什么是例1和例2之间的区别?我从来没有使用过的的extern 的函数原型,但看着别人的code(谁是方式更有经验比我)我看到的的extern 的总是声明函数原型时使用。任何人都可以点请点有什么区别? (或点我一个链接,我可以找到具体的信息)。谷歌说,这是涉及到外部链接的东西。任何人都可以指向我一个例子,其中一个将工作和其他的就没有呢?
What is the difference between case 1 and case 2? I never used extern for function prototypes but looking at someone's code (who is way more experienced than I am) I see extern always used when declaring the function prototype. Can anyone point please point the difference? (or point me to a link where I can find specific information). Google says that is something related to the external linkage. Can anyone point me to an example where one would work and the other wouldn't?
我使用的嵌入式C(KEIL),如果这有什么差别。
I am using embedded C (KEIL), if it makes any difference.
推荐答案
的extern
是全球联动联动说明。其对应的是静态
,指定文件的本地联动。由于全球联动是在C默认值,加入的extern
的声明使一个函数的声明没有区别。对于一个变量是prevents自动内存分配和使用它要的只是的在全局范围内声明一个变量的唯一途径。
extern
is a linkage specifier for global linkage. Its counterpart is static
, which specifies file-local linkage. Since global linkage is the default in C, adding extern
to the declaration makes no difference for the declaration of a function. For a variable it prevents automatic memory allocation and using it is the only way to just declare a variable at global scope.
如果你只是谷歌的关键词,你会发现如许多文章这个:
If you just google the keyword, you will find many articles e.g. this one:geeks for geeks
这篇关于上的extern函数原型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!