gpt4 book ai didi

c++ - AMD64 ABI 中的空类会怎样?

转载 作者:太空狗 更新时间:2023-10-29 21:46:00 25 4
gpt4 key购买 nike

我正在查看 AMD64 ABI而且它似乎没有指定如何传递空类类型。对于空类成员函数,似乎 this 照常传递,但对于空类,Clang 生成的代码似乎只是简单地忽略了此类。根据 AMD64 ABI,这是否正确?

最佳答案

虽然不清楚问题到底是什么,但关于 C++ ABI 是什么,答案非常明确:

For the C++ ABI we will use the IA-64 C++ ABI and instantiate it appropriately. The current draft of that ABI is available at:

Link to current location of Itanium ABI spec

这是说:

Empty classes will be passed no differently from ordinary classes. If passed in registers the NaT bit must not be set on all registers that make up the class.

The contents of the single byte parameter slot are unspecified, and the callee may not depend on any particular value. On Itanium, the associated NaT bit must not be set if the parameter slot is associated with a register.

这里有另一个提示:

A result of an empty class type will be returned as though it were a struct containing a single char, i.e. struct S { char c; };. The actual content of the return register is unspecified. On Itanium, the associated NaT bit must not be set.

因此,一个空类应该被视为包含单个字符的结构,但永远不会使用该单个字符。

当然,clang 中可能存在关于空类的错误。尽管我对此表示怀疑,但公平地说。

关于c++ - AMD64 ABI 中的空类会怎样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16189106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com