外部联系 [英] externl linkage

查看:42
本文介绍了外部联系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"如果块内标识符的声明不包含extern说明符,则标识符没有链接,并且对于函数是唯一的。如果它确实包含extern,并且外部声明在块周围的范围内是活动的,那么标识符与外部声明具有相同的链接,并且引用相同的对象或函数;但如果没有外部声明可见,则其链接是外部的。


这是来自K& R的声明。

任何人都可以向我解释这个陈述吗?请举个例子。

Thanx

"If a declaration for an identifier within a block does not include the extern specifier, then the identifier has no linkage and is unique to the function. If it does include extern, and an external declaration for is active in the scope surrounding the block, then the identifier has the same linkage as the external declaration, and refers to the same object or function; but if no external declaration is visible, its linkage is external."

this is a statement from K&R.
Can anyone explain me this statement??kindly give an example.
Thanx

推荐答案

这意味着什么是大括号之间的任何变量{int var;这是一对大括号的本地。这就是没有联系的意思。


但是,如果变量有外部像{extern int var;然后变量(var)不在大括号之间,但在大括号之外。在这种情况下,必须有一个名为var的可共享变量(称为外部链接)。


但如果省略extern关键字,则变量将恢复为第一种情况。也就是说,一个局部变量。


Linkage处理范围{}之间是否共享某些东西。


没有联系意味着不可共享在当前{}之外。

静态链接意味着内部链接,这意味着只能在定义变量的源文件中共享。

可共享链接意味着外部链接,这意味着可以在另一个链接中共享源文件。
What this means is that any variable between braces {int var; } is local to that pair of braces. That is what is mean by no linkage.

However, if the variable has extern like { extern int var; } then the variable (var) is not between the braces but is outside the braces. In this case there has to be a sharable variable (called external linkage) named var.

But if you omit the the extern keyword, then the variablwe reverts to the first case. That is, a local variable.

Linkage deals with whether something is shared or not between scopes { }.

No linkage means not sharable outside the current { }.
Static linkage means internal linkage which means sharable only in the source file that defines the variable.
Sharable linkage means external linkage which means sharable in another source file.


" for在块周围的范围内是活动的

这部分是什么意思?我对这个有疑问。
"for is active in the scope surrounding the block"
what does this part mean?? i had a doubt on this one.


那是什么部分?我无法找到您的K& R报价。
What section is that? I am having trouble finding your K&R quote.


这篇关于外部联系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆