Call conventions _ cdecl and _ stdcall

Source: Internet
Author: User

First, __ cdecl, c Declaration, and C style statement. Or C default calling ). (So the question is, why is the Pascal style called STD ?)

The call conventions include three points: the order of parameters in and out of the stack, who is responsible for the stack play, and the method for generating the function name (renaming ?)

1.

In the parameter stack order, the difference between __cdecl and _ stdcall is from right to left;

2.

_ Cdecl is the default value of C/C ++. Let's recall the variable-length parameter function like printf in STL. Only the caller can know the real parameter, therefore, it is more appropriate for the caller to recover the stack.

The conclusion is that __cdecl specifies that the caller is responsible for the stack.

Go down ......

The caller is responsible for the stack, which means that in the final executable code, all the calls to the method specified as _ cdecl will generate a piece of code to clean the stack relative to _ stdcall.

In other words, if a Windows API acts as an existing system/binary code/or something else, when it calls a function provided by an application, there is no way to know how to clean up the stack (callback/winapi) provided by programmers,

It is even more difficult to add the code for processing stacks to this set of existing "system/binary code/or anything else". Therefore, the function provider must process stacks on its own.

This is why callback/winapi is _ stdcall.

3.

.

 

Call conventions _ cdecl and _ stdcall

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.