The calling convention (calling convention) is a relatively low-level design in computer programming, which mainly involves:
- Is the function parameter passed through the register or the stack?
- is the function parameter left-to-right or right-to-left stack?
- Whether variadic functions are supported (vararg function or variadic).
- Do you need a function prototype?
- Does the caller (caller) or the callee (called or callee) clean up the stack?
There are several calling conventions in C and C + +: __cdecl, __stdcall, __fastcall, __thiscall, __clrcall, __vectorcall. Below are some of the calling conventions.
__cdecl
C Declaration Calling Convention,c declares the calling convention. It is the default calling convention for C and C + +. Characteristics:
- The stack is purged by the caller (manually cleared).
- Parameters are stacked from right to left.
- Variable parameters are supported (the function itself does not know how many parameters it has, so the caller needs to clear it).
- The post-compilation function name is adapted to: "_ Function name". such as _funcname.
__stdcall
Standard calling convention, normal calling convention. Characteristics:
- The caller clears the stack.
- Parameters are right-to-sit-down stacks (as with __cdecl), and if the member function of the class is called, it is finally pressed into the this pointer.
- A function prototype is required and the argument function is not supported.
- Function name Adaptation: "_ Function name @ parameter byte size decimal". such as [email protected].
__fastcall
Fast calling convention, Quick call Convention. Solve efficiency problems by using registers. Characteristics:
- The function parameter section is passed through the register, and the leftmost two DWORD in the function (the register size is a double word) or a smaller parameter is passed through the register. The remaining stack passes from right to left.
- Function name adaptation: "@ Function name @ function parameter byte size decimal".
- Returned in the same way as __stdcall.
__thiscall
Primarily used to resolve this pointer problem, use the register to pass the this pointer. Returned in the same way as __stdcall.
__clrcall
__clrcall is C + +. NET inside.
__vectorcall
Requires that parameters be passed in the register whenever possible. The function name is adapted to "@@ 函数 name @ parameter byte number decimal". This is the standard that Microsoft has added itself.
Summarize
In addition to __cdecl (and __clrcall), the other is the callee clears the stack.
C and C + + calling convention