为什么Go语言的编译器“gc”使用与C语言不同的调用约定?

huangapple go评论80阅读模式
英文:

Why does go's compiler "gc" use a different calling convention than C?

问题

C使用cdecl,我已经研究过并从汇编中调用过它。它感觉还不错,那为什么要破坏兼容性呢?为什么需要另一种约定?

英文:

C uses the cdecl, which I've looked into and called with from assembly. It feels well enough, so why break the compatibility? Why was another convention needed?

答案1

得分: 5

因为具有相同的调用约定没有优势。即使调用约定相同,Go代码和C代码也不能直接互相调用,因为Go使用了分割堆栈。

另一方面,在gccgo中这是有意义的,因为gcc支持某些架构的C分割堆栈。而且,据我所知,调用约定是因为兼容性的原因。(更多详细信息在这里。)

免责声明:我从未真正使用过gccgo。

英文:

Because there's no advantage in having the same calling convention. Go code and C code cannot call each other directly even when the calling convention would be the same because Go uses split stacks.

OTOH, it makes sense in gccgo, as gcc supports C split stacks for some architectures. And, IIRC, there the calling convention is because of that compatible. (More details here.)

Disclaimer: I didn't ever actually used gccgo.

huangapple
  • 本文由 发表于 2013年4月1日 06:44:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/15735439.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定