__stdcall, __cdecl, and __fastcall are three function invocation protocols, which affect the way the function parameters are stacked, how the data is purged in the stack, the modifiers of the compiler function names, and so on. As shown, you can set the default calling protocol for all functions in the IDE environment, and you can set the invocation protocol of this function separately when the function is defined.
- Calling protocol common occasions
-
- __stdcall:windows API default function call protocol.
- __cdecl:c/c++ the default function call protocol.
- __fastcall: Suitable for applications where performance requirements are high.
- function parameter in stack mode
-
- __stdcall: Function arguments are left-right into the stack.
- __cdecl: Function arguments are left-right into the stack.
- __fastcall: Parameters that are not greater than 4 bytes from the left are placed into the CPU's ECX and edx registers, and the remaining parameters are stacked from right to left.
- Problem one: __fastcall in the register to put not more than 4 bytes of parameters, it is high performance, suitable for applications that require high performance.
- In-Stack data removal method
-
- __stdcall: After the function call is finished, the data inside the stack is purged by the called function.
- __CDECL: After the function call is finished, the data inside the stack is cleared by the function caller.
- __fastcall: After the function call is finished, the data inside the stack is purged by the called function.
- Problem one: Different compiler sets the stack structure is not the same, across the development platform by the function caller to clear the stack of data is not OK.
- Problem two: The parameters of some functions are mutable, such as the printf function, which can only be cleared by the function caller of the data in the stack.
- Problem three: When the caller clears the data in the stack, each call contains code that clears the data in the stack, so the executable file is larger.
- C language Compiler function name decoration rules
-
- __stdcall: After compiling, the function name is modified to "[email protected]".
- __CDECL: After compilation, the function name is decorated as "_functionname".
- __fastcall: After compiling, the function name is decorated with "@[email protected]".
- Note: "functionname" is the function name and "number" is the parameter byte count.
- Note: Function calls cannot be implemented if a different function call protocol is used when the function is implemented and the function is defined.
- C + + language compiler function name decoration rules
- __stdcall: After compiling, the function name is decorated as "? [Email protected] @YG ******@z ".
- __CDECL: After compiling, the function name is decorated as "? [Email protected] @YA ******@z ".
- __fastcall: After compiling, the function name is decorated as "? [Email protected] @YI ******@z ".
- Note: "******" returns the value type and the parameter type table for the function.
- Note: Function calls cannot be implemented if a different function call protocol is used when the function is implemented and the function is defined.
- The C and C + + languages are not able to invoke each other's functions without special processing.
Original address: http://blog.sina.com.cn/s/blog_701526f40100lcy6.html
The difference between "__stdcall", "C + +", __cdcel and __fastcall