打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
What does GCC __attribute__((mode(XX)) actually do?
userphoto

2013.01.23

关注

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 2xsizeof(uint32_t) for a dword in 32-bit systems and 2*sizeof(uint64_t) for 64-bit systems, am I correct?


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:

QI: An integer that is as wide as the smallest addressable unit, usually 8 bits.

HI: An integer, twice as wide as a QI mode integer, usually 16 bits.

SI: An integer, four times as wide as a QI mode integer, usually 32 bits.

DI: An integer, eight times as wide as a QI mode integer, usually 64 bits.

SF: A floating point value, as wide as a SI mode integer, usually 32 bits.

DF: A floating point value, as wide as a DI mode integer, usually 64 bits.

So DI is essentially sizeof(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 essentially sizeof(char) * 16 (128 bits).

share|improve this answer
Just what I needed, +1. Is there no "standard" way to get around this then, I take it? i.e. declare say a 128-bit type? In its current usage, we can dword = word << 1 safely and easily; I'd rather not replace that with a function etc if I can help it. – Sadaluk Dec 30 '10 at 0:31
@Ninefingers: In GCC you can use __int128 I believe: gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html. – Matthew Iselin Dec 30 '10 at 0:34
@Ninefingers: GCC supports the extension types __int128_t and __uint128_t (at least on 64-bit platforms, not sure about 32-bit targets) – Stephen Canon Dec 30 '10 at 14:19
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
_attribute_((packed))
VFB_变量类型
C语言宏定义使用技巧
DELPHI7.0获取硬盘、CPU、网卡序列号 - XpFox's Blog
MFC 获取磁盘剩余空间
从内存中加载DLL DELPHI版
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服