Define Constructor explicitly can affect compile behavior when return a object by value?
<p>test environment: vs 2008, debug mode</p>

<p>test code is:</p>

<pre><code>// a demo for return value

class C
{
public:
    int value;
    int value2;
    int value3;

    //C(int v=0): value(v) {};
};

C getC(int v)
{
    C c1;

    return c1;
}



int main()
{
    C c1 = getC(10);

    return 0;
}
</code></pre>

<p>and the asm output is:</p>

<pre><code>; 39   :    C c1 = getC(10);

push    10                  ; 0000000aH
lea eax, DWORD PTR $T2595[ebp]
push    eax
call    ?getC@@YA?AVC@@H@Z          ; getC
add esp, 8
mov ecx, DWORD PTR [eax]
mov DWORD PTR $T2594[ebp], ecx
mov edx, DWORD PTR [eax+4]
mov DWORD PTR $T2594[ebp+4], edx
mov eax, DWORD PTR [eax+8]
mov DWORD PTR $T2594[ebp+8], eax
mov ecx, DWORD PTR $T2594[ebp]
mov DWORD PTR _c1$[ebp], ecx
mov edx, DWORD PTR $T2594[ebp+4]
mov DWORD PTR _c1$[ebp+4], edx
mov eax, DWORD PTR $T2594[ebp+8]
mov DWORD PTR _c1$[ebp+8], eax
</code></pre>

<p>From the asm output, we can see the compile create 2 temporary object.</p>

<p>However, when I define the constructor explicitly as follow:</p>

<pre><code>C(int v=0): value(v) {};
</code></pre>

<p>and recompiled the program, the asm output is become:</p>

<pre><code>; 39   :    C c1 = getC(10);

push    10                  ; 0000000aH
lea eax, DWORD PTR _c1$[ebp]
push    eax
call    ?getC@@YA?AVC@@H@Z          ; getC
add esp, 8
</code></pre>

<p>Obviously, the compiler optimize the code, and my question is:</p>

<p>I just add the constructor explicitly, Why it can affect the compile behavior of return object by value?</p>
