69,373
社区成员
发帖
与我相关
我的任务
分享
typedef struct _test_B_s {
unsigned int u32_a;
unsigned int u32_b;
}test_B_t;
int main(int argc, char *argv[])
{
test_B_t st_a;
memset(&st_a, 0, sizeof(st_a));
st_a.u32_a = 0xaaaa0000;
st_a.u32_b = 0x0000bbbb;
test_B_t *pst = &st_a;
printf("pst:0x%08x, pst[0]:0x%08x, pst:0x%08x\n", pst, pst[0], pst);
return 0;
}
common_test.o: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 e4 f0 and $0xfffffff0,%esp
6: 83 ec 30 sub $0x30,%esp
9: c7 44 24 28 00 00 aa movl $0xaaaa0000,0x28(%esp)
10: aa
11: 8b 54 24 28 mov 0x28(%esp),%edx
15: 8d 44 24 28 lea 0x28(%esp),%eax
19: c7 44 24 2c bb bb 00 movl $0xbbbb,0x2c(%esp)
20: 00
21: 8b 4c 24 2c mov 0x2c(%esp),%ecx
25: 89 44 24 14 mov %eax,0x14(%esp)
29: 89 44 24 08 mov %eax,0x8(%esp)
2d: 89 54 24 0c mov %edx,0xc(%esp)
31: 89 4c 24 10 mov %ecx,0x10(%esp)
35: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
3c: 00
3d: c7 04 24 01 00 00 00 movl $0x1,(%esp)
44: e8 fc ff ff ff call 45 <main+0x45>
49: 31 c0 xor %eax,%eax
4b: c9 leave
4c: c3 ret
#include<stdio.h>
typedef struct _test_B_s {
unsigned int u32_a;
unsigned int u32_b;
}test_B_t;
int main(int argc, char *argv[])
{
test_B_t st_a;
memset(&st_a, 0, sizeof(st_a));
st_a.u32_a = 0xaaaa0000;
st_a.u32_b = 0x0000bbbb;
test_B_t *pst = &st_a;
printf("pst:0x%08x, pst[0]:0x%08x,pst:0x%08x\n", pst, pst->u32_a,pst);
return 0;
}
说明我刚才的理解是正确的。。。
#include<stdio.h>
typedef struct _test_B_s {
unsigned int u32_a;
unsigned int u32_b;
}test_B_t;
int main(int argc, char *argv[])
{
test_B_t st_a;
memset(&st_a, 0, sizeof(st_a));
st_a.u32_a = 0xaaaa0000;
st_a.u32_b = 0x0000bbbb;
test_B_t *pst = &st_a;
printf("pst:0x%08x, pst[0]:0x%08x,pst:0x%08x,pst:0x%08x\n", pst, pst[0],pst[2],pst);
return 0;
}
说明一个问题是,printf在读取结构体时,把整个结构体读入到了缓存中。但是第一个只打印出a,缓存中仍然存在着b的数据,于是下一个打印出b,不管是什么参数。此时如果在打印出pst,可以发现,又回到正常情况,打印出pst地址。
我是这么理解的。不知道对不对。