Stdcall, cdecl, and Pascal are different.

Source: Internet
Author: User

Cdecl is used by the caller to clear the stack.
Stdcall clears the stack from the called Function
Fastcall puts the first three parameters in the function parameter list into the register eax, EDX, ECx, and other parameter pressure stacks.

_ Stdcall and _ cdecl
Almost every Windows API function we write is of the _ stdcall type. First, we need to know the difference between the two: Stack (stack, A storage structure ). After the function call is complete, the stack needs to be cleared. Here is the key to the problem. How can we clear it ?? If our function uses _ cdecl, the stack clearing is done by the caller. In terms of COM, it is done by the customer. This brings about a difficult problem. Different compilers may generate stacks in different ways. Can the caller complete the cleanup work normally? The answer is no. If _ stdcall is used, the above problem is solved, and the function solves the clearing work by itself. Therefore, in cross-platform (Development) calls, we use _ stdcall (although sometimes it appears as winapi ). So why do we still need _ cdecl? When the parameters of such a function, such as fprintf (), are variable and variable, the caller cannot know the length of the parameter in advance, and the cleanup operation afterwards cannot proceed normally, therefore, we can only use _ cdecl in this case. Here we have a conclusion that if yourProgramVariable parameters are not involved, it is best to use the _ stdcall keyword.

In addition:
_ Cdecl
The parameter is pushed from right to left to the stack. The caller pushes the parameter to the stack. For a "C" function or variable, the modifier name is underlined before the function name. The "C ++" function is different.
For example, the modified name of function void test (void) is _ test. For a global function that does not belong to a class, what is the modified name? Test @ zaxxz.
This is the default MFC call convention. Because the caller is responsible for popping up the parameter stack, you can define a variable number of parameters for the function, such as the printf function.

Like Pascal, stdcall is Pascal's call habit.
The parameter is pushed from right to left to the stack. The parameter is pushed to the stack by the caller. For a "C" function or variable, the modifier name is prefixed with the following line, followed by the function name, followed by the symbol "@" and the number of bytes of the parameter, such as the function int func (int, double B) the modifier is _ FUNC @ 12. The "C ++" function is different.

 

 

Http://zhidao.baidu.com/question/107145682.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.