• Advertisement
Sign in to follow this  

__stdcall Class Constructor

This topic is 1929 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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? Edited by greenvertex

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement