MS Visual C++:什么时候应该关心使用调用约定?

发布于 2024-10-13 17:25:14 字数 191 浏览 4 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千秋岁 2024-10-20 17:25:14

一般来说,当您集成由不同编译器编译的代码时,调用约定非常重要。例如,如果您要发布一个供客户使用的 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).

薄情伤 2024-10-20 17:25:14

您无需关心 64 位应用程序,因为只有一种调用约定。

在以下情况下,您确实需要关心 32 位应用程序:

  • 您与第 3 方库交互,并且这些库的标头未声明正确的调用约定。
  • 您正在创建一个库或 DLL 供其他人使用。您需要决定调用约定,以便其他代码在调用您的代码时可以使用正确的调用约定。

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:

  • You interact with 3rd party libraries and the headers for these libraries did not declare the correct calling convention.
  • You are creating a library or DLL for someone else to use. You need to decide on a calling convention so that other code would use the correct calling convention when calling your code.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文