#include <stdio.h> #include <stdlib.h> int wei; //未初始化的全局變量,bss區 int you = 0; //初始化為0的全局變量,bss區 int qing = 1; //初始化非0的全局變量,data區 int main() { static int ai; //未初始化的靜態局部變量,bss區 static int ni = 0; //初始化為0的靜態局部變量,bss區 static int everyday = 2; //初始化為非0的靜態局部變量,data區 int forever; //棧(stacks) return 0; }
將main.c編譯為匯編語言:gcc main.c -o main.o
objdump -t main.o | grep "\.data" 0000000000600800 l d .data 0000000000000000 .data 0000000000600808 l O .data 0000000000000004 everyday.2553 0000000000600800 w .data 0000000000000000 data_start 0000000000600800 g .data 0000000000000000 __data_start 0000000000600804 g O .data 0000000000000004 qing
objdump -t main.o | grep "\.bss" 0000000000600810 l d .bss 0000000000000000 .bss 0000000000600810 l O .bss 0000000000000001 completed.6364 0000000000600818 l O .bss 0000000000000008 dtor_idx.6366 0000000000600824 l O .bss 0000000000000004 ni.2552 0000000000600828 l O .bss 0000000000000004 ai.2551 0000000000600820 g O .bss 0000000000000004 you 000000000060082c g O .bss 0000000000000004 wei