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)>