哪里静态局部变量去 [英] Where do static local variables go

查看:126
本文介绍了哪里静态局部变量去的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里存储在内存中静态局部变量?局部变量只能在声明它们的函数内部访问。

Where are static local variables stored in memory? Local variables can be accessed only inside the function in which they are declared.

全局静态变量进入。数据段。

Global static variables go into the .data segment.

如果静态全局和静态局部变量的两个名称相同,编译器如何区分它们?

If both the name of the static global and static local variable are same, how does the compiler distinguish them?

推荐答案

静态变量进入同一网段为全局变量。这两者之间唯一不同的是,编译器隐藏,从连接器的所有静态变量:只有EXTERN的名称(全局)变量得到曝光。这是编译器如何让具有相同名称的静态变量在不同的翻译单元存在。静态变量的名称在编译阶段仍然未知,但随后他们的数据被放置到。数据段匿名的。

Static variables go into the same segment as global variables. The only thing that's different between the two is that the compiler "hides" all static variables from the linker: only the names of extern (global) variables get exposed. That is how compilers allow static variables with the same name to exist in different translation units. Names of static variables remain known during the compilation phase, but then their data is placed into the .data segment anonymously.

这篇关于哪里静态局部变量去的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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