Alex Rivera | Logout

What is the meaning and usage of __stdcall?

Asked 2009-08-20T14:03:10.130
95

I've come across __stdcall a lot these days.

MSDN doesn't explain very clearly what it really means, when and why should it be used, if at all.

I would appreciate if someone would provide an explanation, preferably with an example or two.

Edit
Report

2 Answers

85

All functions in C/C++ have a particular calling convention. The point of a calling convention is to establish how data is passed between the caller and callee and who is responsible for operations such as cleaning out the call stack.

The most popular calling conventions on windows are

  • __stdcall, Pushes parameters on the stack, in reverse order (right to left)
  • __cdecl, Pushes parameters on the stack, in reverse order (right to left)
  • __clrcall, Load parameters onto CLR expression stack in order (left to right).
  • __fastcall, Stored in registers, then pushed on stack
  • __thiscall, Pushed on stack; this pointer stored in ECX

Adding this specifier to the function declaration essentially tells the compiler that you want this particular function to have this particular calling convention.

The calling conventions are documented here

Raymond Chen also did a long series on the history of the various calling conventions (5 parts) starting here.

answered 2009-08-20T14:07:52.307
3

It specifies a calling convention for a function. A calling convention is a set of rules how parameters are passed to a function: in which order, per address or per copy, who is to clean up the parameters (caller or callee) etc.

answered 2009-08-20T14:07:28.843

Your Answer