引用的传递方式

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:

因为身体状况,沒心情看书,得闲无聊看下引用是怎么传递的,结果还是很无聊,还是地址。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值