我反汇编了下5: int i=5,j=5,p,q;
004109B8 mov dword ptr [ebp-4],5 // i = (ebp-4) = 5
004109BF mov dword ptr [ebp-8],5 // j = (ebp-8) = 5
6: p=(i++)+(i++)+(i++);
004109C6 mov eax,dword ptr [ebp-4] // eax = i = 5
004109C9 add eax,dword ptr [ebp-4] // eax = i + eax = 5+5=10
004109CC add eax,dword ptr [ebp-4] // eax = i + eax = 10+5=15
004109CF mov dword ptr [ebp-0Ch],eax // p = (ebp-0ch) = eax = 15
004109D2 mov ecx,dword ptr [ebp-4] // ecx = i = 5
004109D5 add ecx,1 // ecx = ecx + 1 = 6
004109D8 mov dword ptr [ebp-4],ecx // i = ecx = 6
004109DB mov edx,dword ptr [ebp-4] // edx = i = 6
004109DE add edx,1 // edx = edx + 1 = 7
004109E1 mov dword ptr [ebp-4],edx // i = edx = 7
004109E4 mov eax,dword ptr [ebp-4] // eax = i = 7
004109E7 add eax,1 // eax = eax + 1 = 8
004109EA mov dword ptr [ebp-4],eax // i = eax = 8
7: q=(++j)+(++j)+(++j);
004109ED mov ecx,dword ptr [ebp-8] // ecx = (ebp-8) = j = 5
004109F0 add ecx,1 // ecx = ecx + 1 = 6
004109F3 mov dword ptr [ebp-8],ecx // j = ecx = 6
004109F6 mov edx,dword ptr [ebp-8] // edx = j = 6
004109F9 add edx,1 // edx = edx + 1 = 7
004109FC mov dword ptr [ebp-8],edx // j = edx = 7
004109FF mov eax,dword ptr [ebp-8] // eax = j = 7
00410A02 add eax,dword ptr [ebp-8] // eax = eax + j = 14
00410A05 mov ecx,dword ptr [ebp-8] // ecx = j = 7
00410A08 add ecx,1 // ecx = ecx + 1 = 8
00410A0B mov dword ptr [ebp-8],ecx // j = ecx = 8
00410A0E add eax,dword ptr [ebp-8] // eax = eax + j = 14 + 8 = 22
00410A11 mov dword ptr [ebp-10h],eax // q = eax = 22
也就是说
p = (i++) + (i++) + (i++); 顺序为p = i+i+i = 15 ,然后 i = i + 1 + 1 + 1 = 8
q = (++j) + (++j) + (++j); 顺序为q = 7 + 7 + 8 = 22, 然后j = j + 1 + 1 + 1 = 8
这是编译器的问题,这种问题研究它没什么意义,不同的编译器可能有不同的结果 |