定义调用约定的意义是什么? [英] What is the point of defining a calling convention?

查看:52
本文介绍了定义调用约定的意义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆