从 C/C++ 语言的角度出发,只要了解对象的存储区分为静态存储(static storage)、自动存储(automatic storage)和动态分配存储(allocated or dynamic storage)就可以了。
如果和操作系统的概念结合起来,自动存储区对应着栈(stack),动态分配存储区对应着堆(heap),静态存储区又可细分为 .bss、.data、.rodata 等段(section)。
(gdb) p &a
$1 = (int *) 0x8049544
(gdb) p &b
$2 = (int *) 0x8049538
(gdb) p &c
$3 = (int *) 0x8049548
(gdb) p &d
$4 = (int *) 0x804954c
(gdb) p &e
$5 = (int *) 0x8049540
(gdb) p &f
$6 = (int *) 0x8049534
(gdb)
int d;
int e = 0;
int f = 10;
int main(int argc, char** argv)
{
static int a=0;
static int b = 10;
static int c;
}
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[22] .data PROGBITS 08049528 000528 000014 00 WA 0 0 4
[23] .bss NOBITS 0804953c 00053c 000014 00 WA 0 0 4
data节加载入内存后从08049528-->08049528+14
.bss节加载入内存后从 0804953c --> 0804953c +14
所以fb位于.data节
eacd位于.bss节
54c d
548 c
544 a
540 e
53c-----------^.bss
538 b
534 f
528-----------^.data
实战linux编程精髓上说的没错。。。。