- 论坛徽章:
- 0
|
程序如下:
#include <stdio.h>
struct D
{
};
int main()
{
struct D d1;
struct D d2;
struct D d3;
printf("%lu\n", sizeof(struct D));
printf("%lu, %p\n", sizeof(d1), &d1);
printf("%lu, %p\n", sizeof(d2), &d2);
printf("%lu, %p\n", sizeof(d3), &d3);
return 0;
}
运行结果:
Ellen$ gcc empty_struct.c
Ellen$ ./a.out
0
0, 0x7fff7f76c62d
0, 0x7fff7f76c62e
0, 0x7fff7f76c62f
问题: 栈空间不是道着走的么? 什么这几个局部结构体变量的地址是递增的呢?
运行环境:
Linux Ellen-MacBookPro 3.5.0-36-generic #57~precise1-Ubuntu SMP Thu Jun 20 18:21:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
gcc版本:
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) |
|