英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论