int b = (++a) * (a++); 等价于 int b = (a++) * (++a);
可解释为 :
++a;
int b = a * a;
a++;
int b = (++a) * (++a);
可解释为
++a;
++a;
int b = a * a;
#include <iostream>
using namespace std;
void func1(int a)
{
int b = (a++) * (++a);
}
void func2(int a)
{
int b = (++a) * (a++);
}
void func3(int a)
{
int b = (a++) * (a++);
}
void func4(int a)
{
int b = (++a) * (++a);
}
int main()
{
return 0;
}
汇编代码
.file "practice3.cpp"
.local _ZStL8__ioinit
.comm _ZStL8__ioinit,1,1
.text
.globl _Z5func1i
.type _Z5func1i, @function
_Z5func1i:
.LFB971:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl %edi, -20(%rbp)
addl $1, -20(%rbp)
movl -20(%rbp), %eax
imull -20(%rbp), %eax
movl %eax, -4(%rbp)
addl $1, -20(%rbp)
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE971:
.size _Z5func1i, .-_Z5func1i
.globl _Z5func2i
.type _Z5func2i, @function
_Z5func2i:
.LFB972:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl %edi, -20(%rbp)
addl $1, -20(%rbp)
movl -20(%rbp), %eax
imull -20(%rbp), %eax
movl %eax, -4(%rbp)
addl $1, -20(%rbp)
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE972:
.size _Z5func2i, .-_Z5func2i
.globl _Z5func3i
.type _Z5func3i, @function
_Z5func3i:
.LFB973:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl %edi, -20(%rbp)
movl -20(%rbp), %eax
imull -20(%rbp), %eax
movl %eax, -4(%rbp)
addl $1, -20(%rbp)
addl $1, -20(%rbp)
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE973:
.size _Z5func3i, .-_Z5func3i
.globl _Z5func4i
.type _Z5func4i, @function
_Z5func4i:
.LFB974:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl %edi, -20(%rbp)
addl $1, -20(%rbp)
addl $1, -20(%rbp)
movl -20(%rbp), %eax
imull -20(%rbp), %eax
movl %eax, -4(%rbp)
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE974:
.size _Z5func4i, .-_Z5func4i
.globl main
.type main, @function
main:
.LFB975:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $0, %eax
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE975:
.size main, .-main
.type _Z41__static_initialization_and_destruction_0ii, @function
_Z41__static_initialization_and_destruction_0ii:
.LFB976:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
cmpl $1, -4(%rbp)
jne .L7
cmpl $65535, -8(%rbp)
jne .L7
movl $_ZStL8__ioinit, %edi
call _ZNSt8ios_base4InitC1Ev
movl $__dso_handle, %edx
movl $_ZStL8__ioinit, %esi
movl $_ZNSt8ios_base4InitD1Ev, %edi
call __cxa_atexit
.L7:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE976:
.size _Z41__static_initialization_and_destruction_0ii, .-_Z41__static_initialization_and_destruction_0ii
.type _GLOBAL__sub_I__Z5func1i, @function
_GLOBAL__sub_I__Z5func1i:
.LFB977:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $65535, %esi
movl $1, %edi
call _Z41__static_initialization_and_destruction_0ii
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE977:
.size _GLOBAL__sub_I__Z5func1i, .-_GLOBAL__sub_I__Z5func1i
.section .init_array,"aw"
.align 8
.quad _GLOBAL__sub_I__Z5func1i
.hidden __dso_handle
.ident "GCC: (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3"
.section .note.GNU-stack,"",@progbits