About function invocation Way ' __stdcall ' and ' __cdecl '

Source: Internet
Author: User
about function Invocation methods __stdcall and __cdecl

On function invocation way __stdcall and __cdecl __stdcall __cdecl the same point and different point instances

__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 same point of the two is the same point as the different points
Parameter stack order is the same: from right to left different point
Stack balance mode is different: __stdcall automatic cleaning stack, __cdecl manual cleaning stack. The return instruction differs: _stdcall uses RETN x, __cdecl the decorated name of a RET compiled function is different: suppose there is a function int foo (int a, int b), the __stdcall compiled function name is _foo@8, and the use of __ Cdecl the compiled function name is _foo. A function of an instance that supports 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 #d Efine apientry WINAPI #define apiprivate __stdcall #define PASCAL __stdcall #define CDECL _cdecl #ifndef C Decl #define CDECL _cdecl #endif 

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.