其中是存储在内存段中的全局变量和静态变量? [英] where is the global and static variables stored in memory segment?

查看:235
本文介绍了其中是存储在内存段中的全局变量和静态变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的链接器脚本中,起始地址和大小如下:

In my linker script the starting address and size are as follows:

code start:90400000
code end:  90a00000
data start:90b00000, size 3MB
bss start: 91200000, size 1MB

但是当我声明一个全局变量,它的地址是: 910bead0
它应该驻留在 .bss 节,但它是别的地方,我甚至没有在链接描述文件中指定。
任何人都可以告诉我发生了什么事?

But when I am declaring a global variable,its address is : 910bead0 It is supposed to reside in .bss section ,but it is somewhere else, which I have not even specified in linker script. Can anyone tell me what is going on?

推荐答案

正在使用,但传统上:初始化的全局数据在 data 中;未初始化的全局数据在 bss 中(将初始化为0)。当你写如下:

You don't indicate what system, etc., you are using, but traditionally: initialized global data goes in data; uninitialized global data goes in bss (which will be 0 initialized). When you write something like:

int x = 0;

系统不同:有些人认为初始化等同于零初始化't指定初始化),并将它放在 bss ;其他人只会看到一个事实,即有一个初始化,并把它放在 data

systems differ: some recognize that the initialization is the equivalent to zero initialization (i.e. what happens when you don't specify the initialization), and will put it in bss; others will just see the fact that there is an initialization, and put it in data.

这篇关于其中是存储在内存段中的全局变量和静态变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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