范围和链接有什么区别? [英] What is the difference between scope and linkage?

查看:54
本文介绍了范围和链接有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了不同的网站,但我不明白.你能用简单的英语解释一下吗?

I tried different websites but I don't get it. Could you explain it in simple english?

推荐答案

"scope" 是编译器的命名空间;链接"是关于编译单元.

"scope" is a namespace of the compiler; "linkage" is about compiled units.

我再解释一下:在函数中声明的变量具有该函数的作用域,即它仅在该函数内可见.在源文件中声明为静态的变量只能由该源文件(以及所有包含的文件!)中的代码看到.变量也可以具有全局作用域:它们可以在源文件中引用,但不在该源文件中声明(分配),而是在另一个源文件中声明.

I explain a bit more: A variable declared in a function has the scope of that function, i.e. it is visible only within that function. A variable declared as static in a source file, can be seen only by the code in that source file (and all included files!). Variables can also have global scope: they can be referred to in a source file, but not declared (allocated) in that source file but declared in another source file.

我们应该说编译单元"而不是源文件",因为它是被编译的 C 源文件,加上所有包含的文件.范围是指编译器在编译单元中可以看到"的所有内容.这些是命名空间.

In stead of "source file" we should say "compilation unit" as it is the C source file being compiled, plus all included files. Scope refers to everything the compiler can "see" in a compilation unit. These are namespaces.

一个项目编译后有许多目标文件,每个编译单元一个.每个都可以引用未在编译单元中声明的变量.链接器现在必须解析目标文件之间的这些引用:链接.

After compilation of a project there are a number of object files, one for each compile unit. Each may refer to variables used that are not declared in the compile unit. The linker must now resolve these references between object files: linkage.

这也适用于函数.

这篇关于范围和链接有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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