In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what are the common function calling conventions of C++ language. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.
Introduction to C++ Language Function Calling Conventions
In C /C++ development, there is no problem with program compilation, but when linking, the report function does not exist, or there is no error in program compilation and linking, but as long as the function in the library is called, stack exceptions will occur. This phenomenon occurs when C and C++ code are mixed or when third-party libraries (not developed in C++) are used in C++ programs, due to the Calling Convention and Decorated Name rules. Function calling conventions determine the order in which function parameters are placed on the stack, and whether the caller function or the called function is responsible for clearing parameters from the stack, while function name modification rules determine what name modification methods the compiler uses to distinguish between different functions. If the calling conventions between functions do not match or the name modifications do not match, the above problems will occur.
The function-calling convention in C++ addresses three main problems:
A. Stacking order of function parameters
B. Clean up the body of the stack (responsible for cleaning up the body of the stack: the function itself or the caller)
C. Function Name Renovation
Calling conventions mainly refer to the way in which functions are called. The function calling conventions of C++ language mainly include stdcall, fastcall, pascal, cdecl, thiscall and so on.
In C++, in order to allow operator overloading and function overloading, the C++ compiler usually rewrites the symbolic name of each entry point according to some rule to allow multiple uses of the same name (with different parameter types or different scopes) without breaking existing C-based linkers. This technique is often referred to as Name mangling or name decoration. C++ compiler vendors usually choose their own name modification scheme.
C++ language common function call convention 1,__stdcall
__stdcall is the abbreviation of StandardCall, which is the standard calling method of C++.__ The rules for stdcall calling conventions are as follows:
A. All parameters are pushed into the stack from right to left. If they are calling class members, the last one pushed into the stack is this pointer.
B. The called function automatically cleans the stack and returns the value in EAX.
C, function modifier name convention:VC will compile the function will add an underscore prefix in front of the function name, add "@" and the number of bytes of the parameter after the function name.
2、__cdecl
__cdecl is the abbreviation of C DECLaration (declaration), indicating the default function call method of C language.__ cdecl invocation convention rules are as follows:
A. All parameters are stacked from right to left.
B. All parameters are cleared by the caller, which is called manual stack clearing. Return value in EAX
C, function modifier name convention:VC will compile the function and add an underscore prefix to the function name
Since the stack is cleaned by the caller, variable parameter functions are allowed, such as int sprintf(char buffer,const char format,...).
3、__fastcall
__fastcall is a fast call convention that passes parameters through registers.__ The rules for fastcall conventions are as follows:
A. Use ECX and EDX to transfer the first two DWORD or smaller parameters, and the remaining parameters are still transferred from the right to the left.
B. The called function cleans the memory stack of the transfer parameters before returning, and the return value is in EAX.
C. Function modifier convention:VC will compile the function with the prefix "@" in front of the function name, and add "@" and the number of bytes of the parameter after the function name.
4、thiscall
thiscall is the only function modifier that cannot be explicitly specified. thiscall can only be used for calling C++ class member functions, and thiscall is also the default calling convention for C++ member functions. Because member function calls also have a this pointer, special handling is necessary.
thiscall invocation convention is as follows:
A. The stack is used to pass parameters, and the parameters are pushed into the stack from right to left. If the number of arguments is definite, the this pointer is passed to the callee via ECX; if the number of arguments is indefinite, the this pointer is pushed onto the stack after all arguments have been pushed.
B. For the variable number of parameters, the caller clears the stack, otherwise the stack is cleared by the called function.
thiscall is not a keyword and programmers cannot use it.
5、__pascal
__pascal language calling convention, like__stdcall, parameters are pushed from right to left, the function itself clears the stack, and the return value is in EAX. VC has been abandoned, it is recommended to use stdcall instead.
About "C++ language common function call convention what" This article is shared here, I hope the above content can have some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.