It seems to me, that MSVS ignores __stdcall directive on my functions. I’m cleaning up the stack manually, but the compiler still append ADD ESP instructions after each CALL.
This is how I declare the function:
extern "C" void * __stdcall core_call(int addr, ...);
#define function(...) (DWORD WINAPI) core_call(12345, __VA_ARGS__)
return function("Hello", 789);
And this is how the output looks like:

(source: server4u.cz)
I’ve marked with arrows redundant ADD instructions, which MSVS automatically append after each call, despite the fact, that cleaining the stack is a callee responsibility (reference: http://en.wikipedia.org/wiki/X86_calling_conventions#List_of_x86_calling_conventions) and this causes the crash of my progrm. If I manually replace the ADD instructions with NOPs, program works as supposed. So, my question is… Is there a way how to force the compiler to stop addaing these instructions?
Thanks.
The problem is here:
, ...).Functions with variable number of arguments cannot be
__stdcall.__stdcallfunctions must remove all their stack arguments from the stack at the end, but they can’t know in advance how much stuff they will receive as parameters.The same holds for
__fastcallfunctions.The only applicable calling convention for functions with variable number of arguments is
__cdecl, where the caller has to remove the stack parameters after the call. And that’s what the compiler uses despite your request to use__stdcall.