调用约定的说明(calling convention)
2007-05-31 15:49
225 查看
1、__stdcall调用约定:函数的参数自右向左通过栈传递,被调用的函数在返回前清理传送参数的内存栈,
2、_cdecl是C和C++程序的缺省调用方式。每一个调用它的函数都包含清空堆栈的代码,所以产生的可执行文件大小会比调用_stdcall函数的大。函数采用从右到左的压栈方式。注意:对于可变参数的成员函数,始终使用__cdecl的转换方式。
3、__fastcall调用约定:它是通过寄存器来传送参数的(实际上,它用ECX和EDX传送前两个双字(DWORD)或更小的参数,剩下的参数仍旧自右向左压栈传送,被调用的函数在返回前清理传送参数的内存栈)。
4、__thiscall仅仅应用于"C++"成员函数。this指针存放于CX寄存器,参数从右到左压。
5、naked call采用1-4的调用约定时,如果必要的话,进入函数时编译器会产生代码来保存ESI,EDI,EBX,EBP寄存器,退出函数时则产生代码恢复这些寄存器的内容。naked call不产生这样的代码。naked call不是类型修饰符,故必须和_declspec共同使用。
Visual C++ Language Reference
Argument Passing and Naming Conventions
Microsoft Specific
All arguments are widened to 32 bits when they are passed. Return values are also widened to 32 bits and returned in the EAX register, except for 8-byte structures, which are returned in the EDX:EAX register pair. Larger structures are returned in the EAX register as pointers to hidden return structures. Parameters are pushed onto the stack from right to left. Structures that are not PODs will not be returned in registers.
The compiler generates prolog and epilog code to save and restore the ESI, EDI, EBX, and EBP registers, if they are used in the function.
For information on how to define your own function prolog and epilog code, see Naked Function Calls.
The following calling conventions are supported by the Visual C/C++ compiler.
2、_cdecl是C和C++程序的缺省调用方式。每一个调用它的函数都包含清空堆栈的代码,所以产生的可执行文件大小会比调用_stdcall函数的大。函数采用从右到左的压栈方式。注意:对于可变参数的成员函数,始终使用__cdecl的转换方式。
3、__fastcall调用约定:它是通过寄存器来传送参数的(实际上,它用ECX和EDX传送前两个双字(DWORD)或更小的参数,剩下的参数仍旧自右向左压栈传送,被调用的函数在返回前清理传送参数的内存栈)。
4、__thiscall仅仅应用于"C++"成员函数。this指针存放于CX寄存器,参数从右到左压。
5、naked call采用1-4的调用约定时,如果必要的话,进入函数时编译器会产生代码来保存ESI,EDI,EBX,EBP寄存器,退出函数时则产生代码恢复这些寄存器的内容。naked call不产生这样的代码。naked call不是类型修饰符,故必须和_declspec共同使用。
Visual C++ Language Reference
Argument Passing and Naming Conventions
Microsoft Specific
All arguments are widened to 32 bits when they are passed. Return values are also widened to 32 bits and returned in the EAX register, except for 8-byte structures, which are returned in the EDX:EAX register pair. Larger structures are returned in the EAX register as pointers to hidden return structures. Parameters are pushed onto the stack from right to left. Structures that are not PODs will not be returned in registers.
The compiler generates prolog and epilog code to save and restore the ESI, EDI, EBX, and EBP registers, if they are used in the function.
Note |
---|
When a struct, union, or class is returned from a function by value, all definitions of the type need to be the same, else the program may fail at runtime. |
The following calling conventions are supported by the Visual C/C++ compiler.
Keyword | Stack cleanup | Parameter passing |
---|---|---|
__cdecl | Caller | Pushes parameters on the stack, in reverse order (right to left) |
__clrcall | n/a | Load parameters onto CLR expression stack in order (left to right). |
__stdcall | Callee | Pushes parameters on the stack, in reverse order (right to left) |
__fastcall | Callee | Stored in registers, then pushed on stack |
__thiscall | Callee | Pushed on stack; this pointer stored in ECX |
相关文章推荐
- __stdcalll——调用约定说明符
- IntelliSense: 调用约定后面不能是嵌套声明符, IntelliSense: 应输入类型说明符 concrt.h 解决方案
- 论调用约定
- php soap扩展最全说明,附天气预报调用的例子
- 函数调用约定1
- (转)C/C++函数调用约定
- 函数的调用约定
- 调用约定__stdcall,__cdecl,_cdecl,_stdcall,__fastcall,_fastcall 区别简介
- (转)函数调用约定和函数名修饰规则
- 论调用约定
- DLL中导出函数(函数名及其调用约定)??
- 几种调用约定
- cdecl, stdcall, pascal,fastcall 调用约定区别
- 浅谈Java中工具类的调用方法及说明书生成方案
- C#中调用Windows API的技术要点说明
- 函数调用约定
- 几种调用约定
- 调用约定明确了栈的恢复责任。嗯,是恢复责任,不是压栈……
- DLL中调用约定和名称修饰
- kindEditor完整认识 PHP上调用并上传图片说明