C++ 什么是符号表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/69112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is a symbol table?
提问by jdt141
Can someone describe what a symbol table is within the context of C and C++?
有人可以在 C 和 C++ 的上下文中描述符号表是什么吗?
采纳答案by Ben Combee
There are two common and related meaning of symbol tables here.
符号表在这里有两个常见且相关的含义。
First, there's the symbol table in your object files. Usually, a C or C++ compiler compiles a single source file into an object file with a .obj or .o extension. This contains a collection of executable code and data that the linker can process into a working application or shared library. The object file has a data structure called a symbol table in it that maps the different items in the object file to names that the linker can understand. If you call a function from your code, the compiler doesn't put the final address of the routine in the object file. Instead, it puts a placeholder value into the code and adds a note that tells the linker to look up the reference in the various symbol tables from all the object files it's processing and stick the final location there.
首先,目标文件中有符号表。通常,C 或 C++ 编译器将单个源文件编译为扩展名为 .obj 或 .o 的目标文件。这包含链接器可以处理到工作应用程序或共享库中的可执行代码和数据的集合。目标文件中有一个称为符号表的数据结构,它将目标文件中的不同项目映射到链接器可以理解的名称。如果从代码中调用函数,编译器不会将例程的最终地址放入目标文件中。相反,它在代码中放入一个占位符值并添加一个注释,告诉链接器从它正在处理的所有目标文件中查找各种符号表中的引用,并将最终位置粘贴在那里。
Second, there's also the symbol table in a shared library or DLL. This is produced by the linker and serves to name all the functions and data items that are visible to users of the library. This allows the system to do run-time linking, resolving open references to those names to the location where the library is loaded in memory.
其次,共享库或 DLL 中还有符号表。这是由链接器生成的,用于命名库用户可见的所有函数和数据项。这允许系统进行运行时链接,将这些名称的打开引用解析到库在内存中加载的位置。
If you want to learn more, I suggest John Levine's excellent book "Linkers and Loaders".link text
如果你想了解更多,我推荐 John Levine 的好书“Linkers and Loaders”。链接文字
回答by Steve Landey
Briefly, it is the mapping of the name you assign a variable to its address in memory, including metadata like type, scope, and size. It is used by the compiler.
简而言之,它是您为变量分配的名称与其在内存中的地址的映射,包括类型、范围和大小等元数据。它由编译器使用。
That's in general, not just C[++]*. Technically, it doesn't always include direct memory address. It depends on what language, platform, etc. the compiler is targeting.
这是一般的,而不仅仅是 C[++]*。从技术上讲,它并不总是包括直接内存地址。这取决于编译器的目标语言、平台等。
回答by Steve Landey
In Linux, you can use command:
在 Linux 中,您可以使用命令:
nm [object file]
nm [目标文件]
to list the symbol table of that object file. From this printout, you may then decipher the in-use linker symbols from their mangled names.
列出该目标文件的符号表。从这个打印输出中,您可以从它们的损坏名称中破译正在使用的链接器符号。
回答by Joe Schneider
The symbol table is the list of "symbols" in a program/unit. Symbols are most often the names of variables or functions. The symbol table can be used to determine where in memory variables or functions will be located.
符号表是程序/单元中的“符号”列表。符号通常是变量或函数的名称。符号表可用于确定变量或函数在内存中的位置。
回答by Allan Wind
Check out the Symbol Tablewikipedia entry.
查看符号表维基百科条目。
回答by rashedcs
Symbol table is an important data structure created and maintained by compilers in order to store information about the occurrence of various entities such as variable names, function names, objects, classes, interfaces, etc.
符号表是编译器为了存储变量名、函数名、对象、类、接口等各种实体出现的信息而创建和维护的重要数据结构。