为什么没有int128_t? [英] Why isn't there int128_t?

查看:2174
本文介绍了为什么没有int128_t?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

若干编译器提供128位的整数类型,但没有我所使用的那些的提供的typedef int128_t 。为什么呢?

据我记得,标准


  • 储量 int128_t 为此

  • 鼓励提供这种类型提供的typedef
  • 实施
  • 强制要求这样的实现提供了一个还会将intmax_t 至少为128位

(而且,我不认为我已经用实际符合最后一点实现)


解决方案

我指的是C标准;我认为C ++标准继承了&LT规则;从C <; stdint.h&GT; / &LT; cstdint&GT / p>

我知道,海湾合作委员会实现了128位有符号和无符号整数,名称 __ int128 无符号__int128 __ int128 是实现定义的关键字)在一些平台上。

即使它提供了一个标准的128位型的实施,该标准没有的需要 int128_t uint128_t 来定义。引述 N1570 C标准的草稿第7.20.1.1:


  

这些类型是可选的。然而,如果实现提供
  整数类型为8的宽度,16,32,或64位,无填充比特,
  和(用于签名的类型),该具有一个二的补
  再presentation,应当定义相应的typedef名称。


ç允许实现来定义的扩展整型的名字是实现定义的关键字。 gcc的 __ int128 无符号__int128 非常相似,扩展整型的标准定义的 - 但是GCC不对待他们的方式。相反,它会将其视为一个语言的扩展。

特别是,如果 __ int128 无符号__int128 扩展整型的,那么GCC将需要定义还会将intmax_t uintmax_t型为这些类型(或某些类型的至少128位宽)。它没有这样做;相反,还会将intmax_t uintmax_t型只有64位。

这是,在我看来,不幸的,但我不相信,这使GCC不合格。没有便携式程序可以依赖于的存在__ int128 ,或任何整数类型宽度大于64位。

A number of compilers provide 128-bit integer types, but none of the ones I've used provide the typedefs int128_t. Why?

As far as I recall, the standard

  • Reserves int128_t for this purpose
  • Encourages implementations that provide such a type to provide the typedef
  • Mandates that such implementations provide an intmax_t of at least 128 bits

(and, I do not believe I've used an implementation that actually conforms to that last point)

解决方案

I'll refer to the C standard; I think the C++ standard inherits the rules for <stdint.h> / <cstdint> from C.

I know that gcc implements 128-bit signed and unsigned integers, with the names __int128 and unsigned __int128 (__int128 is an implementation-defined keyword) on some platforms.

Even for an implementation that provides a standard 128-bit type, the standard does not require int128_t or uint128_t to be defined. Quoting section 7.20.1.1 of the N1570 draft of the C standard:

These types are optional. However, if an implementation provides integer types with widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a two’s complement representation, it shall define the corresponding typedef names.

C permits implementations to defined extended integer types whose names are implementation-defined keywords. gcc's __int128 and unsigned __int128 are very similar to extended integer types as defined by the standard -- but gcc doesn't treat them that way. Instead, it treats them as a language extension.

In particular, if __int128 and unsigned __int128 were extended integer types, then gcc would be required to define intmax_t and uintmax_t as those types (or as some types at least 128 bits wide). It does not do so; instead, intmax_t and uintmax_t are only 64 bits.

This is, in my opinion, unfortunate, but I don't believe it makes gcc non-conforming. No portable program can depend on the existence of __int128, or on any integer type wider than 64 bits.

这篇关于为什么没有int128_t?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆