Argument Passing and Naming Conventions

原文:https://docs.microsoft.com/zh-cn/cpp/cpp/argument-passing-and-naming-conventions?view=vs-2017

Visual C++ Compilers允许functions和callers之间约定passing arguments和return values的convention,有的平台并不支持某种convention,在大多数情况下,keywords或者compiler会将不支持的convention更换为default convention。

在x86平台上,所有的参数都被扩展为32bits传递,返回值也同样是32bits,并且存储在EAX register中,并返回,except for 8-byte structures, which are returned in the EDX:EAX register pair.更大的机构体将以指针的形式存储在EAX register中,并返回。Parameters将从右向左入棧,Structures that are not PODs will not be returned in registers.

如果某段代码被引用,compiler将生成prolog和epilog来存储和还原在ESI、EDI、EBX和EBP寄存器中的??(是Parameters吗??)。

备注

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.

For information on how to define your own function prolog and epilog code, see Naked Function Calls.

For information about the default calling conventions in code that targets x64 platforms, see Overview of x64 Calling ConventionsFor information about calling convention issues in code that targets ARM platforms, see Common Visual C++ ARM Migration Issues.

The following calling conventions are supported by the Visual C/C++ compiler.

KeywordStack cleanupParameter passing
__cdeclCallerPushes parameters on the stack, in reverse order (right to left)
__clrcalln/aLoad parameters onto CLR expression stack in order (left to right).
__stdcallCalleePushes parameters on the stack, in reverse order (right to left)
__fastcallCalleeStored in registers, then pushed on stack
__thiscallCalleePushed on stack; this pointer stored in ECX
__vectorcallCalleeStored in registers, then pushed on stack in reverse order (right to left)

For related information, see Obsolete Calling Conventions.


 

疑问:

ESI、EDI、EBX和EBP等等各种寄存器是干嘛?

  • Assembly Language Step-by-Step: Programming with Linux中可以找到答案。。。

WinDef.h中的定义如下:

#ifdef _MAC
#define CALLBACK PASCAL
#define WINAPI CDECL
#define WINAPIV CDECL
#define APIENTRY WINAPI
#define APIPRIVATE CDECL
#ifdef _68K_
#define PASCAL __pascal
#else
#define PASCAL
#endif
#elif (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)
#define CALLBACK __stdcall
#define WINAPI __stdcall
#define WINAPIV __cdecl
#define APIENTRY WINAPI
#define APIPRIVATE __stdcall
#define PASCAL __stdcall
#else
#define CALLBACK
#define WINAPI
#define WINAPIV
#define APIENTRY WINAPI
#define APIPRIVATE
#define PASCAL pascal
#endif

转载于:https://www.cnblogs.com/adasada/p/9827785.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值