Files
Sec-Interview/Chapter23/23-4.md
T
2025-09-25 04:02:19 +08:00

11 lines
862 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
### .bss 段存放哪些数据
`.bss` 段,即未初始化数据段(**B**lock **S**tarted by **S**ymbol),主要存放**未初始化的全局变量和静态变量**
`.bss`段的特殊之处在于,它在可执行文件中**不占用任何实际的磁盘空间**。它只在可执行文件中有一个占位符,告诉操作系统在加载程序时需要为这块区域分配多大的内存。当程序被加载到内存后,操作系统会为 `.bss` 段分配一片连续的内存空间,并且会**自动将其所有字节初始化为零**
这种设计是为了节省可执行文件的大小。如果一个程序有很多未初始化的全局变量,将它们全部写进文件会非常浪费空间,因为它们的值都是已知的(默认是0)
- **例子**
- `int uninitialized_global;`
- `static char static_array[1024];`