GCC __attribute__((mode(XX)) 实际上做了什么?
这是由今天早些时候关于 bignum 库和 gcc 对 C 语言的特定 hack 主题的问题引起的。具体来说,使用了这两个声明:
typedef unsigned int dword_t __attribute__((mode(DI)));
在 32 位系统上和
typedef unsigned int dword_t __attribute__((mode(TI)));
在 64 位系统上。
我认为鉴于这是对 C 语言的扩展,因此没有办法实现它在当前(C99)标准中实现的任何功能。
所以我的问题很简单:这个假设正确吗?这些语句对底层内存做了什么?我认为结果是我在 32 位系统中为 dword
提供了 2*sizeof(uint32_t)
,为 2*sizeof(uint64_t)
为64位系统,我说得对吗?
This arose from a question earlier today on the subject of bignum libraries and gcc specific hacks to the C language. Specifically, these two declarations were used:
typedef unsigned int dword_t __attribute__((mode(DI)));
On 32 bit systems and
typedef unsigned int dword_t __attribute__((mode(TI)));
On 64-bit systems.
I assume given this is an extension to the C language that there exists no way to achieve whatever it achieves in current (C99) standards.
So my questions are simple: is that assumption correct? And what do these statements do to the underlying memory? I think the result is I have 2*sizeof(uint32_t)
for a dword
in 32-bit systems and 2*sizeof(uint64_t)
for 64-bit systems, am I correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些允许您显式指定类型的大小,而不依赖于编译器或机器语义,例如“long”或“int”的大小。
此页面对它们进行了相当详细的描述。
我引用该页面的内容:
所以
DI
本质上是sizeof(char) * 8
。可以在此处找到更多说明,包括
TI
模式 (可能比第一个链接更好,但两者都仅供参考)。因此,TI 本质上是 sizeof(char) * 16(128 位)。
旧链接现已失效,因此这里是官方 GCC 文档< /a>.
These allow you to explicitly specify a size for a type without depending on compiler or machine semantics, such as the size of 'long' or 'int'.
They are described fairly well on this page.
I quote from that page:
So
DI
is essentiallysizeof(char) * 8
.Further explanation, including
TI
mode, can be found here (possibly better than the first link, but both provided for reference).So
TI
is essentiallysizeof(char) * 16
(128 bits).The old links are now dead, so here's the official GCC documentation.
@haelix刚刚读了这个问题,我也试图理解这个事情。根据我的阅读:你可以在GCC源代码树的[gcc/gcc/machmode.def]中找到定义。对于“SD”,它应该是:
“DECIMAL_FLOAT_MODE”说:
@haelix Just read this question and I also tried to understand this thing. By my reading: you can find the definitions in the [gcc/gcc/machmode.def] in GCC source tree. For 'SD' it should be:
and 'DECIMAL_FLOAT_MODE' says: