Skip to main content
GameDev.net gamedev.net
🔒 Locked

__stdcall Class Constructor

Started by greenvertex Oct 9, 2012 at 12:49 AM 2 replies 2.7k views
Original Post
greenvertex
greenvertex
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?
Pointer2APointer
Pointer2APointer
_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.
greenvertex
greenvertex
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?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.