MS Visual C++:什么时候应该关心使用调用约定?
在 C/C++ 中(具体来说,我使用的是 MSVS),在什么情况下需要担心为函数定义指定调用约定?它们重要吗?编译者是否能够在必要时选择最佳约定(即快速调用等)。
也许我的理解不够,但我只是不知道程序员什么时候需要关心参数在堆栈上的放置顺序等问题。我也不明白为什么编译器的优化无法选择最适合该特定函数的方案。任何人可以向我提供的任何知识都会很棒。谢谢!
In C/C++ (specifically, I'm using MSVS), in what situation would one ever need to worry about specifying a calling convention for a function definition? Are they ever important? Isn't the complied capable of choosing the optimal convention when necessary (ie fastcall, etc).
Maybe my understanding is lacking, but I just do not see when their would be a case that the programmer would need to care about things like the order that the arguments are placed on the stack and so forth. I also do not see why the compiler's optimization would not be able to choose whatever scheme would work best for that particular function. Any knowledge anyone could provide me with would be great. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,当您集成由不同编译器编译的代码时,调用约定非常重要。例如,如果您要发布一个供客户使用的 DLL,您将需要确保导出的函数都具有一致的、预期的调用约定。
您是正确的,在单个程序中,编译器通常可以选择每个函数使用哪种调用约定(并且规则通常非常简单)。
In general terms, the calling convention is important when you're integrating code that's being compiled by different compilers. For example, if you're publishing a DLL that will be used by your customers, you will want to make sure that the functions you export all have a consistent, expected calling convention.
You are correct that within a single program, the compiler can generally choose which calling convention to use for each function (and the rules are usually pretty simple).
您无需关心 64 位应用程序,因为只有一种调用约定。
在以下情况下,您确实需要关心 32 位应用程序:
You do not need to care for 64-bit applicatins since there is only one calling convention.
You do need to care for 32-bit applications in the following cases: