cdecl,_stdcall,__fastcall, __thiscall区别简介

__thiscall

转自:http://msdn.microsoft.com/zh-cn/library/ek8tkfbw

The __thiscall calling convention is used on member functions and is the default calling convention used by C++ member functions that do not use variable arguments. Under__thiscall, the callee(被调用函数) cleans the stack, which is impossible forvararg functions. Arguments are pushed on the stack from right to left, with thethis pointer being passed via register ECX, and not on the stack, on the x86 architecture.

One reason to use __thiscall is in classes whose member functions use__clrcall by default. In that case, you can use__thiscall to make individual member functions callable from native code.

When compiling with /clr:pure, all functions and function pointers are__clrcall unless specified otherwise.

In releases before Visual C++ 2005, the thiscall calling convention could not be explicitly specified in a program, becausethiscall was not a keyword.

vararg member functions use the __cdecl calling convention. All function arguments are pushed on the stack, with thethis pointer placed on the stack last

Because this calling convention applies only to C++, there is no C name decoration scheme.

On Itanium Processor Family (IPF) and x64 machines, __thiscall is accepted and ignored by the compiler; on an IPF chip, by convention, parameters are passed in register.

For non-static class functions, if the function is defined out-of-line, the calling convention modifier does not have to be specified on the out-of-line definition. That is, for class non-static member methods, the calling convention specified during declaration is assumed at the point of definition.

// thiscall_cc.cpp
// compile with: /c /clr:oldSyntax
struct CMyClass {
   void __thiscall mymethod();
   void __clrcall mymethod2();
};


 

 

 

你可能感兴趣的:(function,Class,Parameters,compiler,methods,Pointers)