C / C ++ function call protocol summary

__stdcall, __ cdecl and __fastcall are three function calls the agreement, the agreement will affect the function call stack mode function parameters, clears the way within the stack data, modifying the rules function name compilers. 1. Call protocol commonly used applications __stdcall: Windows API function calls the default protocol. __cdecl: C / C ++ function calls the default protocol. __fastcall: suitable for high performance requirements of the occasion. 2. The function parameters stack mode __stdcall: Drawing function parameters from right to left. __cdecl: Drawing function parameters from right to left. __fastcall: not more than 4 from the left byte Parameter into ECX and EDX registers of the CPU, the remaining parameters Drawing from right to left. One problem: __ fastcall into parameter not greater than 4 bytes in the register, so higher performance for applications requiring high performance. 3. Clear the way in the stack data __stdcall: After the function call cleanup stack within the data by the called function. __cdecl: After the function call cleanup stack within the data by the function caller. __fastcall: After the function call within the data cleanup stack by the called function. One problem: different set of compiler stack structure is not the same, when developing cross-platform cleared by the caller of the function within the stack data is not feasible. Question two: the parameters of certain functions is variable, such as printf function, this function can only be cleared within the data stack by the function caller. Question three: When the cleanup stack within the data by the caller, each call contains cleanup code in the stack data, so a larger executable file. 4.C language compiler function name mangling rules __stdcall: After compilation, the function name is modified to "_functionname @ number".





















__cdecl: After compilation, the function name is modified to "_functionname".
__fastcall: After compilation, the function name to be modified to "@ functionname @ nmuber".
Note: "functionname" as a function name, "number" parameter is the number of bytes.
Note: If you define the function implementation and functions of the function call using a different protocol, you can not realize the function call. 5.C ++ compiler function name mangling rules __stdcall: After compilation, the function name is modified to "functionname @@ YG ****** @ Z? ". __cdecl: After compilation, the function name is modified to "functionname @@ YA ****** @ Z? ". __fastcall: After compilation, the function name is modified to "functionname @@ YI ****** @ Z? ". Note: "******" is the function returns a value table and parameter types. Note: If you define the function implementation and functions of the function call using a different protocol, you can not realize the function call. Between the C language and C ++ language if not special treatment, it can not be achieved call each function.







Guess you like

Origin www.cnblogs.com/ivan06/p/11328727.html