calling convention cheat sheet
January 21, 2010 Leave a comment
cdecl, stdcall, fastcall, c++
Overgeneralization, but may be helpful.
- cdecl: parameters right to left on the stack, caller places parameters and removes parameters. gcc uses this.
- stdcall: similar to cdecl, but callee removes function parameters from the stack when finished. Advantage, clean up code doesn’t need to be rewritten for each function. disadvantage, unknown number of parameters are impossible (printf) Microsoft compilers use this
- fastcall stdcall, but uses two parameters in cpu registers (ecx and then edx)
- c++ ‘this’ is passed in ecx (ms visual c++) or passed as first parameter (g++)
More handy is this: http://en.wikipedia.org/wiki/X86_calling_conventions
awesome