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 的方向
x86 下的 struct 變數 member 擺放位置

reference

http://wp.mlab.tw/?p=312

相关文章:

  • 2022-03-01
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-25
  • 2021-11-26
  • 2022-01-12
  • 2022-03-02
  • 2021-07-29
相关资源
相似解决方案