int a=5;
b=++a*--a;
执行步骤:
1: ++a
//a=6
2: --a
//a=5
3: a*a
//b=25
反汇编代码:
mov
eax,dword ptr [a]
add
eax,1
mov
dword ptr [a],eax
mov
ecx,dword ptr [a]
sub
ecx,1
mov
dword ptr [a],ecx
mov
edx,dword ptr [a]
imul
edx,dword ptr [a]
mov
dword ptr [b],edx
int a=5,j,k;
b=(j=++a)*--a;
1: ++a
//a=6
2: j=a
//j=a=6
3: --a
//a=5
4: b=j*a
//b=30
mov
eax,dword ptr [a]
add
eax,1
mov
dword ptr [a],eax
mov
ecx,dword ptr [a]
mov
dword ptr [j],ecx
mov
edx,dword ptr [a]
sub
edx,1
mov
dword ptr [a],edx
mov
eax,dword ptr [j]
imul
eax,dword ptr [a]
mov
dword ptr [b],eax
int a=5;
b=++a*a;
1: ++a
//a=6
2: b=a*a
//b=36
mov
eax,dword ptr [a]
add
eax,1
mov
dword ptr [a],eax
mov
ecx,dword ptr [a]
imul
ecx,dword ptr [a]
mov
dword ptr [b],ecx
int a=5;
b=(a-0)*++a;
1: ++a
//a=6
2: Temp=a-0
//Temp=6
3: b=Temp*a
//b=36
mov
eax,dword ptr [a]
add
eax,1
mov
dword ptr [a],eax
mov
ecx,dword ptr [a]
imul
ecx,dword ptr [a]
mov
dword ptr [b],ecx
int a=5;
b=(a-1)*++a
1: ++a
//a=6
2: Temp=a-1
//Temp=5
3: b=Temp*a
//b=30
mov
eax,dword ptr [a]
add
eax,1
mov
dword ptr [a],eax
mov
ecx,dword ptr [a]
sub
ecx,1
imul
ecx,dword ptr [a]
mov
dword ptr [b],ecx
(环境:VS2008)
除非你知道编译器在做什么,否则这样的代码是没有意义的
[[it] 本帖最后由 Syunxiacc 于 2008-9-9 00:23 编辑 [/it]]