About function Invocation methods __stdcall and __cdecl detailed _c language

Source: Internet
Author: User

About function call Way __stdcall and __cdecl detailed

__stdcall

__cdecl

The similarities and differences between the two points

Instance

__stdcall

__stdcall's full name is standard call. is the standard invocation method for C + +.

function parameters are in the stack order from right to left. function returns with the RETN x instruction, where x is the number of bytes to adjust the stack. This method is called Automatic clearing stack. That is, the number of parameters of the called function is fixed, the caller must strictly follow the definition of the pass parameters, one is not much, a lot.

__cdecl

__cdecl's full name is C declaration, which is the default function invocation of C language.

function parameters are in the stack order from right to left. function to act as a RET instruction when returning functions. Manually clearing the stack by the caller. The called function supports variable parameters. The caller manually balances the stack based on the number of arguments passed in at the time of the call.

The similarities and differences between the two points

Same point

Parameter stack order is the same: from right to left

Different points

Stack balance mode is different: __stdcall automatic cleaning stack, __cdecl manual cleaning stack.

Return instruction is different: _stdcall uses RETN x, __CDECL uses RET

The decorated name of the compiled function is different: suppose there is a function int foo (int a, int b), with the __stdcall compiled function named _foo@8, and the __cdecl compiled function named _foo.

Instance

Functions that support variable parameters must be defined as __cdecl, such as:

int printf (char *fmt, ...);

Definition of __stdcall and __cdecl in windef.h

 #define CALLBACK   __stdcall
 #define WINAPI    __stdcall
 #define WINAPIV   __cdecl
 #define Apientry   WINAPI
 #define Apiprivate  __stdcall
 #define PASCAL    __stdcall
 #define CDECL _ Cdecl
 #ifndef cdecl
 #define CDECL _cdecl
 #endif

The above is a small series for you to bring about the function of the way __stdcall and __cdecl the full content of the detailed, I hope to help you, a lot of support cloud Habitat Community ~

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.