class A
{
public:
int x,y,z;
};
int a;
void f(A &refA)
{
refA.x = 1;
}
void fx(int &refInt)
{
refInt = 2;
}
int main()
{
A theA;
int theInt = 9;
f(theA);
fx(theInt);
return 1;
}
.file "Untitled1.cpp"
.globl _a
.bss
.align 4
_a:
.space 4
.text
.globl __Z1fR1A
.def __Z1fR1A; .scl 2; .type 32; .endef
__Z1fR1A:
LFB0:
pushl %ebp
LCFI0:
movl %esp, %ebp
LCFI1:
movl 8(%ebp), %eax ;将theA的地址放到%eax中,在这里也是refA.x的地址;因为前面的call指令和pushl %ebp 栈中的地址将-4再-4;所以8(%ebp)就是之前的栈顶
movl $1, (%eax)
leave
LCFI2:
ret
LFE0:
.globl __Z2fxRi
.def __Z2fxRi; .scl 2; .type 32; .endef
__Z2fxRi:
LFB1:
pushl %ebp
LCFI3:
movl %esp, %ebp
LCFI4:
movl 8(%ebp), %eax ;取得theInt所在的栈的地址
movl $2, (%eax) ;赋值
leave
LCFI5:
ret
LFE1:
.def ___main; .scl 2; .type 32; .endef
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
LFB2:
pushl %ebp
LCFI6:
movl %esp, %ebp
LCFI7:
andl $-16, %esp
LCFI8:
subl $32, %esp
LCFI9:
call ___main
movl $9, 16(%esp) ;theInt放在了 16(%esp)中
leal 20(%esp), %eax
movl %eax, (%esp) ;将20(%esp)的地址放在了栈顶 应该就是theA的地址了
call __Z1fR1A
leal 16(%esp), %eax ;取得theInt的在栈中的地址
movl %eax, (%esp) ;将theInt的地址放到栈顶
call __Z2fxRi
movl $1, %eax
leave
LCFI10:
ret
LFE2:
因为身体状况,沒心情看书,得闲无聊看下引用是怎么传递的,结果还是很无聊,还是地址。