There is a small section of disassembly after the call to the constructor, that does not make any sense. Here it is,
.text:011A18F0 loc_11A18F0: ; CODE XREF: main+5Bj
.text:011A18F0 mov [ebp+again_obj], 0
.text:011A18FA
.text:011A18FA loc_11A18FA: ; CODE XREF: main+6Ej
.text:011A18FA mov eax, [ebp+again_obj]
.text:011A1900 mov [ebp+var_104], eax
.text:011A1906 mov [ebp+var_4], 0FFFFFFFFh
.text:011A190D mov ecx, [ebp+var_104]
.text:011A1913 mov [ebp+var_14], ecx
.text:011A1916 mov eax, [ebp+var_14]
.text:011A1919 mov [ebp+var_E0], eax
.text:011A191F mov ecx, [ebp+var_E0]
.text:011A1925 mov [ebp+var_EC], ecx
.text:011A192B cmp [ebp+var_EC], 0
.text:011A1932 jz short loc_11A1949
I don’t understand why 0FFFFFFFFh is moved into var_4, and why a lot of values are moved in and out of the variables, the way it is done here. The optimization has been turned of and I compiled the source code on a VS2010 platform.
var_4is an internal variable (I’ll call it ‘_state‘) which tracks the state of constructed objects for unwinding in case the exception happens. What you see is a common pattern made by VC++ when dealing with new’ed objects. E.g.is converted to something like this:
As you see, it’s set to some value (e.g. 0) after a block of memory for the object is new’ed but the object is not constructed yet. This way, if an exception happens in the constructor, the exception handler will free the allocated memory automatically. After the construction it’s set to -1, which roughly corresponds to “the automatic stuff is done, now all memory management is in the programmer’s hands”.
See here for more details (“C++ Exception Model Implementation” and “Sample Program with C++ Exceptions”).