怎么样.bss段未初始化为零 [英] how about .bss section not zero initialized
问题描述
因为我们知道.bss段包含未初始化的变量。如果C code,程序设计师在使用前初始化变量。随后的.bss是没有必要执行C $ C $在C之前是零。
as we know .bss contains un-initialized variables. if in c code, programer initialize the variables before using them. then .bss is not necessary to be zero before executing C code.
我说得对不对?
感谢
推荐答案
在C code,具有静态存储持续时间的变量定义在规范中被初始化为0(第6.7.8初始化,第10段)
In C code, any variable with static storage duration is defined to be initialized to 0 by the spec (Section 6.7.8 Initialization, paragraph 10):
如果有静态存储持续时间的对象不明确初始化,然后:
If an object that has static storage duration is not initialized explicitly, then:
- 如果有指针类型,它被初始化为空指针;
- 如果有算术类型,它被初始化为(正或无符号)为零;
- 如果它是一个聚合,每个成员被初始化(递归)根据这些规则;
- 如果它是一个联盟,首批命名部件(递归)根据这些规则进行初始化。
有些程序加载器将填补用零整节开始,和其他人将填补其按需作为一个性能比较完善。所以,当你在技术上是正确的,因为的.bss
部分不得的真正的包含所有零当C code开始执行时,它的逻辑的一样。在任何情况下,假设你有一个符合标准的工具链,你可以把它看作是全零。
Some program loaders will fill the whole section with zeroes to start with, and others will fill it 'on demand' as a perfomance improvement. So while you are technically correct that the .bss
section may not really contain all zeroes when the C code starts executing, it logically does. In any case, assuming you have a standard compliant toolchain, you can think of it as being all zero.
这是初始化为非零值的任何变量将永远不会在的.bss
部分结束;他们在处理的。数据
或 .RODATA
部分,这取决于它们的具体特点。
Any variables that are initialized to non-zero values will never end up in the .bss
section; they are handled in the .data
or .rodata
sections, depending on their particular characteristics.
这篇关于怎么样.bss段未初始化为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!