__stdcall 和 __cdecl 的区别

kingtsui 2001-04-28 03:25:00
能否说的详细点
...全文
108 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
taolei 2001-04-28
  • 打赏
  • 举报
回复
kingtsui:
被调用函数在返回时直接清栈。
例如:
ret 10h

就表示该函数有4个参数,返回后ESP再加16个byte.
kingtsui 2001-04-28
  • 打赏
  • 举报
回复
需不需要是一回事,怎么实现是另一回事
我可没有问需不需要啊!

函数调用怎么可能不清栈呢?
liu_feng_fly 2001-04-28
  • 打赏
  • 举报
回复
在你的代码里不用考虑这些事情的!
kingtsui 2001-04-28
  • 打赏
  • 举报
回复
__stdcall不需要清栈吗?
tlovexyj 2001-04-28
  • 打赏
  • 举报
回复
This is the default calling convention for C and C++ programs. Because the stack is cleaned up by the caller, it can do vararg functions. The __cdecl calling convention creates larger executables than __stdcall, because it requires each function call to include stack cleanup code. The following list shows the implementation of this calling convention.

Element Implementation
Argument-passing order Right to left
Stack-maintenance responsibility Calling function pops the arguments from the stack
Name-decoration convention Underscore character (_) is prefixed to names
Case-translation convention No case translation performed


Note For related information, see Decorated Names.

Place the __cdecl modifier before a variable or a function name. Because the C naming and calling conventions are the default, the only time you need to use __cdecl is when you have specified the /Gz (stdcall) or /Gr (fastcall) compiler option. The /Gd compiler option forces the __cdecl calling convention.

Example
In the following example, the compiler is instructed to use C naming and calling conventions for the system function:

// Example of the __cdecl keyword
_CRTIMP int __cdecl system(const char *);

lazyeric 2001-04-28
  • 打赏
  • 举报
回复
我在这里用了某位大侠的话:
_cdecl
C/C++的缺省调用协定,由调用者清理堆栈,这就是C/C++中可以使
用可变参数的函数的原因,所有参数自右至左入栈,生成的代码中
函数名有一个_(下划线)作前缀。
_stdcall
Win32 API的调用协定,由被调用的函数清理堆栈,所有参数自右至
左入栈,生成的代码中函数名有一个_(下划线)作前缀一个@和参数总
字节数(十进制)作後缀。它不支持可变参数,但它产生的代码比
_cdecl的短,因为没有每次调用後的清理堆栈的代码。
tlovexyj 2001-04-28
  • 打赏
  • 举报
回复
The __stdcall calling convention is used to call Win32 API functions. The callee cleans the stack, so the compiler makes vararg functions __cdecl. Functions that use this calling convention require a function prototype. The following list shows the implementation of this calling convention.

Element Implementation
Argument-passing order Right to left.
Argument-passing convention By value, unless a pointer or reference type is passed.
Stack-maintenance responsibility Called function pops its own arguments from the stack.
Name-decoration convention An underscore (_) is prefixed to the name. The name is followed by the at sign (@) followed by the number of bytes (in decimal) in the argument list. Therefore, the function declared as int func( int a, double b ) is decorated as follows: _func@12
Case-translation convention None


The /Gz compiler option specifies __stdcall for all functions not explicitly declared with a different calling convention.

Functions declared using the __stdcall modifier return values the same way as functions declared using __cdecl.

END Microsoft Specific

Example
In the following example, use of __stdcall results in all WINAPI function types being handled as a standard call:

// Example of the __stdcall keyword
#define WINAPI __stdcall

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧