2 int main()3 {4 struct _test {5 int a;6 int b;7 int c;8 };9 10 struct _test test;11 test.a = 1;12 test.b = 2;13 test.c = 3;14 15 printf("test.a = %d, test.b=%d, test.c=%d\n", test.a, test.b, test.c);16 17 return 0;18 }
(gdb) p &test.a$1 = (int *) 0x7fffffffddb0(gdb) p &test.b$2 = (int *) 0x7fffffffddb4(gdb) p &test.c$3 = (int *) 0x7fffffffddb8
conclusion
愈前面的變數,出現在 memory 愈低的 memory address愈後面的變數,出現在 memory 愈高的 memory address符合 heap 由 低 address 往 高 address 的方向
reference
http://wp.mlab.tw/?p=312
即使是不成熟的尝试,也胜于胎死腹中的策略。