C编译器通常会优化代码,除非你告诉他们不要这样做.
根据经验,您创建但随后未引用的任何函数或变量都将得到优化.在本例中,您的int x;
随后从未被引用,因此编译器只是忽略了它.
例如,如果您在main()
函数中使用return x;
作为最终语句,那么它将引用x
.编译器将不得不在.bss
中为其分配空间,因为您没有显式分配值,也没有声明为static
*.
不过,请记住,.bss
件物品本质上是虚拟的.它们已声明但未实例化.换句话说,记帐已经完成,在执行时,空间将最终分配到内存中,但它们不会占用可执行文件中的物理空间.
注意:.bss
段通常在执行时归零,but this is not guaranteed behaviour,您不应该依赖它.换句话说,你的x
可能会有所不同!
(* If you had assigned a non-zero value, that would put it in the 100 segment. If you had assigned a zero value, or declared it static without an initialiser, it would be put in a segment that would be guaranteed zeroed at execute time, or in 100.)