i = i++

8  	    i = i++;
0x0040135D	mov    -0xc(%ebp),%eax
0x00401360	lea    0x1(%eax),%edx
0x00401363	mov    %edx,-0xc(%ebp)
0x00401366	mov    %eax,-0xc(%ebp)
#include <stdio.h>
#include <iostream>
using namespace std;

main()
{
    int i = 0;
    i = i++;
    cout << i << endl;
}
output:
0
#include <iostream>
using namespace std;
struct A{
    static int  x;
    int  y;
public:
    A operator ++(int){ return A(x++, y++); //构造一个匿名类 }
    A(int x, int y){ A::x=x;  A::y=y; }
};


int A::x=2;
int  main( ){
    A a(54, 3);
    cout << A::x << "  " << a.y << endl;
    a++;
    cout << A::x << "  " << a.y << endl;
    return 0;
}
output:
54  3
54  4
// 汇编代码
0x00427EFC<span style="white-space:pre">	</span>push   %ebp
0x00427EFD<span style="white-space:pre">	</span>mov    %esp,%ebp
0x00427EFF<span style="white-space:pre">	</span>sub    $0x28,%esp
0x00427F02<span style="white-space:pre">	</span>mov    %ecx,-0x1c(%ebp)
// 取值
0x00427F05<span style="white-space:pre">	</span>mov    -0x1c(%ebp),%eax
0x00427F08<span style="white-space:pre">	</span>mov    (%eax),%edx
// 加一放到原地址
0x00427F0A<span style="white-space:pre">	</span>lea    0x1(%edx),%ecx
0x00427F0D<span style="white-space:pre">	</span>mov    -0x1c(%ebp),%eax
0x00427F10<span style="white-space:pre">	</span>mov    %ecx,(%eax)
// 取值
0x00427F12<span style="white-space:pre">	</span>mov    0x473000,%eax
0x00427F17<span style="white-space:pre">	</span>lea    0x1(%eax),%ecx
0x00427F1A<span style="white-space:pre">	</span>mov    %ecx,0x473000
0x00427F20<span style="white-space:pre">	</span>lea    -0xc(%ebp),%ecx
// 压栈的二个数是没有加一的而二个数
0x00427F23<span style="white-space:pre">	</span>mov    %edx,0x4(%esp)
0x00427F27<span style="white-space:pre">	</span>>mov    %eax,(%esp)
// 重新构造一个匿名类
0x00427F2A<span style="white-space:pre">	</span>call   0x427edc <A::A(int, int)>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值