定义调用约定的意义是什么? [英] What is the point of defining a calling convention?
问题描述
例如:
int WINAPI WinMain(HINSTANCE实例,HINSTANCE prev_instance,PSTR cmd_line,int cmd_show)
WINAPI是一个如下所示的定义:
#define WINAPI __stdcall
你为什么不能做
int __stdcall WinMain(HINSTANCE实例,HINSTANCE prev_instance,PSTR cmd_line,int cmd_show)
实际上,我认为我的问题是我对typedef的定义感到困惑.谁可以给我解释一下这个?定义有什么作用,为什么您不能只写__stdcall呢?
因为 WINAPI
调用约定不能保证作为 __ stdcall
.使用 WINAPI
的代码即使没有使用,也仍然是正确的.
您可以如您在后面的示例中那样编写函数,并且可以正常工作-这不是一个好习惯,也不能移植到调用约定是其他东西的平台上./p>
For example:
int WINAPI WinMain ( HINSTANCE instance, HINSTANCE prev_instance, PSTR cmd_line, int cmd_show )
WINAPI is a a define that looks like this:
#define WINAPI __stdcall
why can't you just do:
int __stdcall WinMain ( HINSTANCE instance, HINSTANCE prev_instance, PSTR cmd_line, int cmd_show )
actually I think my problem is that I'm sort of confusing defines with typedef's. Can someone explain this to me? what does the define do and why can't you just write __stdcall in its place?
Because the WINAPI
calling convention is not guaranteed to be __stdcall
. Code that uses WINAPI
will still be correct even when it isn't.
You can write the function as in your latter example, and it'd work fine - it's just not good practice and would not be portable to a platform where the calling convention is something else.
这篇关于定义调用约定的意义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!