This is a bit hard for me to read, so bear with me.
#include <stdio.h>class MyVector{ public: int m_x; int m_y; MyVector(int px, int py) { m_x = px; m_y = py; }; void operator++(int) { m_x++; m_y++; }; void operator++() { ++m_x; ++m_y; }; void operator+=( MyVector & param ) { m_x += param.m_x; m_y += param.m_y; };};int main(int argc, char ** argv){ MyVector a(0, 0); MyVector b(1, 1); printf("(%i,%i)\n", a.m_x, a.m_y); a++; ++a; a+=b; printf("(%i,%i)\n", a.m_x, a.m_y); return 0;}
.file "testinc.cpp" .def ___main; .scl 2; .type 32; .endef .textLC0: .ascii "(%i,%i)\12\0" .align 2.globl _main .def _main; .scl 2; .type 32; .endef_main: pushl %ebp movl %esp, %ebp subl $24, %esp andl $-16, %esp movl $0, %eax movl %eax, -20(%ebp) movl -20(%ebp), %eax call __alloca call ___main subl $4, %esp pushl $0 pushl $0 leal -8(%ebp), %eax pushl %eax call __ZN8MyVectorC1Eii addl $16, %esp subl $4, %esp pushl $1 pushl $1 leal -16(%ebp), %eax pushl %eax call __ZN8MyVectorC1Eii addl $16, %esp subl $4, %esp pushl -4(%ebp) pushl -8(%ebp) pushl $LC0 call _printf addl $16, %esp subl $8, %esp pushl $0 leal -8(%ebp), %eax pushl %eax call __ZN8MyVectorppEi addl $16, %esp subl $12, %esp leal -8(%ebp), %eax pushl %eax call __ZN8MyVectorppEv addl $16, %esp subl $8, %esp leal -16(%ebp), %eax pushl %eax leal -8(%ebp), %eax pushl %eax call __ZN8MyVectorpLERS_ addl $16, %esp subl $4, %esp pushl -4(%ebp) pushl -8(%ebp) pushl $LC0 call _printf addl $16, %esp movl $0, %eax leave ret .section .text$_ZN8MyVectorC1Eii,"x" .linkonce discard .align 2.globl __ZN8MyVectorC1Eii .def __ZN8MyVectorC1Eii; .scl 2; .type 32; .endef__ZN8MyVectorC1Eii: pushl %ebp movl %esp, %ebp movl 8(%ebp), %edx movl 12(%ebp), %eax movl %eax, (%edx) movl 8(%ebp), %edx movl 16(%ebp), %eax movl %eax, 4(%edx) popl %ebp ret .section .text$_ZN8MyVectorppEi,"x" .linkonce discard .align 2.globl __ZN8MyVectorppEi .def __ZN8MyVectorppEi; .scl 2; .type 32; .endef__ZN8MyVectorppEi: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax incl (%eax) movl 8(%ebp), %eax incl 4(%eax) popl %ebp ret .section .text$_ZN8MyVectorppEv,"x" .linkonce discard .align 2.globl __ZN8MyVectorppEv .def __ZN8MyVectorppEv; .scl 2; .type 32; .endef__ZN8MyVectorppEv: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax incl (%eax) movl 8(%ebp), %eax incl 4(%eax) popl %ebp ret .section .text$_ZN8MyVectorpLERS_,"x" .linkonce discard .align 2.globl __ZN8MyVectorpLERS_ .def __ZN8MyVectorpLERS_; .scl 2; .type 32; .endef__ZN8MyVectorpLERS_: pushl %ebp movl %esp, %ebp movl 8(%ebp), %ecx movl 8(%ebp), %edx movl 12(%ebp), %eax movl (%eax), %eax addl (%edx), %eax movl %eax, (%ecx) movl 8(%ebp), %ecx movl 8(%ebp), %edx movl 12(%ebp), %eax movl 4(%eax), %eax addl 4(%edx), %eax movl %eax, 4(%ecx) popl %ebp ret .def __ZN8MyVectorpLERS_; .scl 3; .type 32; .endef .def __ZN8MyVectorppEv; .scl 3; .type 32; .endef .def __ZN8MyVectorppEi; .scl 3; .type 32; .endef .def _printf; .scl 2; .type 32; .endef .def __ZN8MyVectorC1Eii; .scl 3; .type 32; .endef
Okay, both __ZN8MyVectorppEi and __ZN8MyVectorppEv, (operator++(int) and operator++()) are identical, as my previous post suggested. ++ isn't defined for floats, so it'd be pointless to try and test them, normal compilers optomize for pre and post increment over integers. I believe __ZN8MyVectorpLERS is operator+=, which had to access another object, so it'd make sense that it would require more opcodes.
_main Is harder to interpret, but it appears as though theres one more opcode between the call to _printf and __ZN8MyVectorppEi, HOWEVER, printf does return the number of characters printed, which I believe is the
pushl $0 opcode, since the two prior opcodes are modifying the stack pointer.
So, for gcc compiler (one that appears to be two years out of date actually, I need to fix that), there are no differences between pre and post increment when used without an order of operations context.