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)05/31 Report--
This article mainly introduces the relevant knowledge of the way of function calls in C++, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe that you will gain something after reading this C++ article on the way of function calls. Let's take a look.
Stdcall is often called pascal calling convention, because pascal is a very common computer programming language for teaching in the early days, its syntax is rigorous, and the function calling convention used is stdcall. It is common to declare this calling convention with PASCAL macros in the Microsoft C++ family of CUniverse + compilers, such as WINAPI and CALLBACK.
C++ object layout and virtual member function calls of polymorphisms
Life cycle of JNI object in function call
Four rules of JavaScript function call
Distinguish between base class and subclass constructor call sequence in inheritance relationship
Visual editor for PHP editor function calls
The calling convention of stdcall means: 1) parameters are pushed into the stack from right to left, 2) the function itself modifies the stack. 3) the function name is automatically underlined with a leading underscore, followed by an @ symbol, followed by the size of the parameter. Take the above function as an example, parameter b is first stacked, then parameter a, and the function call function (1) will be translated into assembly language:
Push ebp saves the ebp register, which will be used to hold the top pointer of the stack. You can restore mov ebp,esp to save the stack pointer mov eax when the function exits. Before ebp points to the location in the [ebp + 8H] stack, ebp,cs:eip,a,b,ebp + 8 points to aadd eax in turn, and bmov esp,ebp recovery esppop ebpret 8 is saved at ebp + 12 in the [ebp + 0CH] stack.
Note that different compilers insert their own assembly code to provide compilation versatility, but in general this is the case. It is a common method for compilers to keep esp to ebp at the beginning of the function and restore at the end of the function. From the point of view of the function call, 2 and 1 are put into the stack by push in turn, and the parameters are accessed through the offset relative to ebp (that is, the stack pointer when the function is just entered). At the end of the function, ret 8 cleans up the 8-byte stack, and the function restores the stack itself.
Cdecl calling convention
The cdecl calling convention, also known as the C calling convention, is the default calling convention of the C language. Its definition syntax is: int function (int b) / / unmodified is the C calling convention int _ _ cdecl function (int a calling int b) / / explicitly indicates the C calling convention.
At the time of writing this article, to my surprise, I found that the parameter stack order of the cdecl calling convention is the same as that of stdcall, and the parameters are first pushed into the stack from the direction to the left. The difference is that the function itself does not clean up the stack, and the caller is responsible for cleaning the stack. Because of this change, the C calling convention allows the number of parameters of the function to be not fixed, which is also a major feature of the C language. For the previous function function, the assembly code after using cdecl becomes:
Note to the caller push 1push 2call functionadd esp,8: here the caller saves the ebp register at the called function _ function in the recovery stack. The register will be used to save the top pointer of the stack and can restore mov ebp,esp when the function exits.
Save the stack pointer mov eax. Before the ebp points to the location in the [ebp + 8H] stack, the ebp,cs:eip,a,b,ebp + 8 points to the aadd eax in turn, and the bmov esp,ebp recovery esppop ebpret is saved at ebp + 12 in the [ebp + 0CH] stack. Note that there is no modification in the stack MSDN. It is said that this modification automatically puts a leading underscore before the function call name, so the function name is recorded as _ function in the symbol table. But I don't seem to see this change when I compile.
This is the end of the article on "what is the way to call functions in C++?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "what is the way to call functions in C++". If you want to learn more knowledge, you are welcome to follow the industry information channel.
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.