• Create Account

### #Actualgreenvertex

Posted 08 October 2012 - 06:51 PM

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."

This was only tested in VS2012 so maybe this stdcall->thiscall behavior is implementation specific?

### #1greenvertex

Posted 08 October 2012 - 06:49 PM

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:  Base base;
0108143E  lea		 ecx,[base]
01081441  call	    Base::Base (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."

This was only tested in VS2012 so maybe this stdcall->thiscall behavior is implementation specific?

PARTNERS