System如何识别不同函数中同名的静态变量? [英] How are static variables with the same name in different functions identified by the System?

查看:21
本文介绍了System如何识别不同函数中同名的静态变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AFAIK,我们可以在不同的函数中有两个同名的静态变量吗?这些是如何由编译器和符号表管理的?他们的身份如何单独管理?

AFAIK, we can have two static variables with the same name in different functions? How are these managed by the compiler and symbol table? How are their identities managed seperately?

推荐答案

编译器不在链接符号表中存储静态变量的名称.就链接器而言,它们只是作为模块一部分的一些内存.(这在所有情况下可能不是 100% 正确,但实际上是正确的)

Compilers don't store static variables' names in the linking symbol table. They are just some memory that is part of the module as far as the linker is concerned. (this may not be 100% true in all cases but it is effectively true)

静态变量的名称通常包含在调试符号表中.

The names of static variables are usually included within the debugging symbol table.

当您将 .c 文件提供给编译器时,它会与所有已知符号的名称保持一致,以便在将来的代码中出现时可以识别它们.它还记住它们,以便它可以提供有用的错误/警告消息,但在生成输出文件时它几乎忘记了它们(除非正在生成调试符号).

When you feed a .c file to the compiler it keeps up with the names of all known symbols so that it can recognize them for what they are when they come up in future code. It also remembers them so that it can give useful error/warning messages, but it pretty much forgets about them when generating output files (unless debugging symbols are being generated).

这篇关于System如何识别不同函数中同名的静态变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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