#include <stdio.h>
struct node
{
int data1;
int data2;
}*a, b;
int main()
{
struct node **p;
b.data1 = 1;
b.data2 = 2;
a = &b;
p = &a;
printf("*p = %0x, **p = %0x, (*p)->data1 = %0x\n", *p, **p, (*p)->data1); //用来打印data1的值应该为1
return 0;
}
执行后打印为:
*p = 8049590, **p = 1, (*p)->data1 = 2 //打出来data2的值
gcc -S 后:
.file "test.c"
.section .rodata
.align 32
.LC0:
.string "*p = %0x, **p = %0x, (*p)->data1 = %0x\n"
.text
.globl main
.type main,@function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $1, b
movl $2, b+4
movl $b, a
movl $a, -4(%ebp)
subl $12, %esp
movl -4(%ebp), %eax
movl (%eax), %eax
pushl (%eax) //push 了data1的值对应C里(*p)->data1
movl -4(%ebp), %eax
movl (%eax), %eax
pushl 4(%eax) //push 了data2的值,为什么会多入栈data2?
pushl (%eax) //push data1的值对应C里的**p
movl -4(%ebp), %eax
pushl (%eax) //push 结构体地址对应C里的*p
pushl $.LC0 //push 打印字符串
call printf
addl $32, %esp
movl $0, %eax
leave
ret
.Lfe1:
.size main,.Lfe1-main
.comm a,4,4
.comm b,8,4
.ident "GCC: (GNU) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)"
为什么在这里回把data2的值多入栈一次? |