调用约定有何不同?

发布于 2025-01-10 06:58:29 字数 157 浏览 0 评论 0原文

据我所知,调用约定取决于平台是Windows还是Linux。

我想知道,

  1. 编译器使调用约定不同。
  2. 平台使调用约定有所不同。

哪一个是真的? 如果只有 2 为真,则调用约定是由平台定义的,编译器是否只遵循定义的约定?

From my knowledge, the calling convention is depending on whether the platform is Windows or Linux.

I wanna know,

  1. Compilers make the calling convention different.
  2. Platforms make the calling convention different.

Which one is true?
if only 2 is true, is the calling convention is defined by the platforms, and do the compilers just follow the defined convention?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

满身野味 2025-01-17 06:58:29

平台通常定义一种或多种“标准”调用约定。如果编译器想要使用这些约定与平台上的其他工具或组件进行互操作,但可以在内部使用自己的不同调用约定,则需要遵循这些约定。

唯一真正的要求是任何调用者和被调用者都需要就他们之间的调用约定达成一致。

Platforms generally define one or more "standard" calling conventions. Compilers need to follow those conventions if they want to interoperate with other tools or components on the platform using those conventions, but can use their own different calling conventions internally.

The only real requirement is that any caller and callee need to agree on the conventions for the call between them.

_失温 2025-01-17 06:58:29

相关:为什么 Windows64 使用与 x86-64 上所有其他操作系统不同的调用约定? 讨论谁定义了调用约定。

在这种情况下,GCC 开发人员实际上代表整个平台决定了 x86-64 System V ABI。

显然,编译器开发人员是最有可能设计出好的编译器的人,但是一旦设定,其他制作新编译器的人如果想要兼容就必须遵循它。

所有非 Windows 操作系统都选择遵循相同的 x86-64 System V 调用约定,因为它设计得非常好,因此它涵盖的平台集逐渐包括所有非 Windows 操作系统。部分原因是它们都使用 GCC 和 GCC 兼容编译器。这并不像不同编译器的开发人员聚集在一起就他们都遵循的该平台的调用约定达成一致,当时(2000 年代初)只有一个主要的免费非 Windows C 编译器。

Related: Why does Windows64 use a different calling convention from all other OSes on x86-64? talks about who defined the calling convention.

In that case, GCC developers effectively decided on behalf of the whole platform for the x86-64 System V ABI.

Obviously compiler devs are the most likely people to be able to design a good one, but once it's set, other people making new compilers have to follow it if they want to be compatible.

All non-Windows OSes chose to follow the same x86-64 System V calling convention because it was pretty well designed, so the set of platforms it covers grew to include all non-Windows OSes. Partly because they all use GCC and GCC-compatible compilers. It's not like developers of different compilers got together to agree on a calling convention they'd all follow for that platform, there was only one major free non-Windows C compiler at that time (early 2000s).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文