__stdcall Class Constructor

Started by
2 comments, last by Pointer2APointer 11 years, 6 months ago
I've seen forms of this around here and there and I don't get it:


class Test {
public:
__stdcall Test()
{
int x = 0;
++x;
}
};
int main(int argc, char** argv)
{
Test t;
return 0;
}


Why is the constructor declared to use the stdcall convention as opposed to thiscall? It doesn't actually seem to affect the assembly in debug mode (the following appears to be thiscall convention):


12: Test t;
0108143E lea ecx,[t]
01081441 call Test::Test (010810E1h)
13:
14: return 0;
01081446 xor eax,eax


And Microsoft seems to confirm:

When you use the __stdcall keyword on a non-static member function, such as a constructor, the compiler will use the thiscall calling convention."[/quote]

This was only tested in VS2012 so maybe this stdcall->thiscall behavior is implementation specific?
Advertisement
_stdcall pushes parameters backwards (right to left) on the stack.

_thiscall gets pushed on the stack, but in normal order, and the this pointer is placed in the ECX register.

They are simply calling conventions for the compiler when generating object code during compilation.
Yes, this is red text.
I understand that, which is why stdcall convention doesn't make a whole lot of sense to me when applied to constructors. I'm simply wondering if there is some implementation out there in which it makes sense (or in which it is even allowed) to forego the this pointer?
As far as I know, you can't forego any this-type reference or pointer to a class object in memory in programming languages(well, at least not in any practical way).

C++ also implements the this pointer as an r-value:

http://en.wikipedia....es_and_r-values
Yes, this is red text.

This topic is closed to new replies.

Advertisement