_ Cdecl ,__ fastcall, _ stdcall what is the difference?

Source: Internet
Author: User

_ Cdecl ,__ fastcall, _ stdcall what is the difference? Please refer to the details.
---------------------------------------------------------------
 
Function parameter stack Entry Method
---------------------------------------------------------------
 
In the function call process, stacks are used, which indicate different stack call methods and release methods.
For example, _ cdecl is the stack calling method of the Standard C method, that is, the parameter pushing to the stack when a function is called is the opposite of the declared order of the function. The other two can be viewed on msdn, however, this does not play a major role in programming.
---------------------------------------------------------------
 
 
Call conventions
 
The call Convention (calling convention) determines the order in which function parameters are pushed to the stack. The caller or the caller pushes the parameter to the stack and generates the function modifier name. MFC supports the following call conventions:
 
 
_ 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.
 
 
_ Stdcall
 
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.
 
All Win32 API functions follow this convention.
 
 
_ Fastcall
 
The first two DWORD types or parameters that occupy less bytes are put into the ECX and EDX registers, and the remaining parameters are pushed to the stack in the order from right to left. The called calls bring up the parameter stack. For "C" functions or variables, the modifier name is prefixed with "@" and then the function name, the symbol "@" and the number of bytes of the parameter are followed. For example, the modifier of the int func (int A, double B) function is @ func @ 12. The "C ++" function is different.
 
In the future, compilers may use different registers to store parameters.
 
 
Thiscall
 
Applies only to "C ++" member functions. This pointer is stored in the Cx register and the parameter is pressed from right to left. Thiscall is not a keyword and cannot be specified by programmers.
 
 
Naked call
 
1-4 call timing. If necessary, when entering the function, the compiler will generate code to save the ESI, EDI, EBX, and EBP registers, when you exit the function, the code is generated to restore the content of these registers. Naked call does not generate such code.
 
The naked call is not a type modifier, so it must be used with _ declspec as follows:
 
_ Declspec (naked) int func (formal_parameters)
 
{
 
// Function body
 
}
 
 
Outdated call conventions
 
Some original call conventions can no longer be used. They are defined as call conventions _ stdcall or _ cdecl. For example:
 
# Define callback _ stdcall
 
# Define winapi _ stdcall
 
# Define winapiv _ cdecl
 
# Define apientry winapi
 
# Define apiprivate _ stdcall
 
# Define Pascal _ 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.