C + +: function call Rule __stdcall,__cdecl,__pascal,__fastcall

Source: Internet
Author: User

__cdecl

__CDECL is the abbreviation for C Declaration, which represents the C language default function call method: All parameters are in the stack from right to left, and these parameters are purged by the caller, called Manual clearing. The called function does not require the caller to pass many arguments, the caller passes too many or too few arguments, and even a completely different parameter does not produce a compile-time error.

__stdcall

__stdcall is the abbreviation for standard calls, which is the standardized call method for C + +: All parameters are in the stack from right to left, and if the class member is called, the last one to stack is the this pointer. The parameters in these stacks are cleared by the called function after it is returned, and the instruction used is retnx,x indicates the number of bytes consumed by the parameter, and the CPU automatically pops up the X-byte stack space after the RET, called Automatic Clearing. function at compile time must determine the number of parameters, and the caller must strictly control the generation of parameters, not more, not less, or return after the error.

__pascal

The __pascal is the Pascal language (Delphi) function call method, also can be used in C + +, the parameter stacking sequence is the opposite of the previous two. The way to return is the same as __stdcall.

__fastcall

__fastcall is a fast-calling method specified by the compiler. Because most function parameters are small, it is time consuming to use stack passes. Therefore, __fastcall usually specifies that the first two (or several) parameters are passed by the register, and the remaining parameters are passed through the stack. Programs compiled by different compilers have different registers, and return methods are equivalent to __stdcall.

__thiscall

__thiscall is required to resolve the pass of this pointer in a class member invocation. __thiscall requires the this pointer to be placed in a specific register, which is determined by the compiler. VC uses Ecx,borland's C + + compiler to use EAX. The return method is equivalent to __stdcall.
The registers involved with __fastcall and __thiscall are determined by the compiler and therefore cannot be used as cross-compiler interfaces. Therefore, the COM object interfaces on Windows are defined as __stdcall invocation methods.

The C language does not state that the default function is __cdecl (only in C), and C + +, but the default invocation method can be set in the IDE environment.

C + +: function call Rule __stdcall,__cdecl,__pascal,__fastcall

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.