A calling convention is a scheme for how functions receive parameters from their caller and how they return a result. The calling conventions can differ in where parameters and return values are placed (in registers; on the call stack; a mix of both), the order they are placed.
Calling conventions describe the interface of called code: - wiki:
Convention | Stack cleanup | Parameter passing | Mangling Style |
---|---|---|---|
__cdecl | Caller | Pushes parameters on the stack, in reverse order (right to left) | _MyFunc |
__stdcall | Callee | Pushes parameters on the stack, in reverse order (right to left) | @MyFunc@Byte |
__fastcall | Callee | Stored in registers, then pushed on stack (right to left) | _MyFunc@Byte |
The fillowing pictures shows the result from three calling conventions when we use the following function - msdn
void calltype MyFunc( char c, short s, int i, double f ); ... void MyFunc( char c, short s, int i, double f ){} ... MyFunc ('x', 12, 8192, 2.7183);
__cdecl : The C decorated function name is "_MyFunc."
__stdcall : The C decorated name (__stdcall) is "_MyFunc@20." The C++ decorated name is proprietary.
__fastcall : The C decorated name (__fastcall) is "@MyFunc@20." The C++ decorated name is proprietary.