uint128_t没有命名类型

我正在将一些代码从C转移到C ++。 在转换期间我遇到了:

uint128_t没有命名类型

我的编译器:gcc版本5.2.1
我的操作系统:Ubuntu 15.1

这个编译好的C和我认为它将通过包括stdint.h解决,但它没有。 到目前为止,我还没有尝试过其他任何事情,因为似乎没有关于此错误的大量信息( 示例 )。 uint128_t在整个程序中使用并且对于构建是必不可少的,因此我无法删除它,并且我不确定使用不同的整数类型。

以下是使用位置和方式的示例。

 union { uint16_t u16; uint32_t u32; uint128_t u128; } value; 

是否可以定义uint128_t或者我应该查看我的编译器?

GCC内置了对__int128类型的__int128unsigned __int128__int128_t__uint128_t (最后两个未记录)。 使用它们来定义您自己的类型:

 typedef __int128 int128_t; typedef unsigned __int128 uint128_t; 

或者,您可以使用__mode__(TI)

 typedef int int128_t __attribute__((mode(TI))); typedef unsigned int uint128_t __attribute__((mode(TI))); 

引用文档 :

TImode

“Tetra Integer”(?)模式表示十六字节整数。

十六字节= 16 * CHAR_BIT> = 128。

我认为这可以通过包含stdint.h来解决,但事实并非如此。

好吧,它可能没有。

首先从C ++ 14,章节cstdint检查C ++头cstdint

 namespace std {..... typedef unsigned integer type uint8_t; // optional typedef unsigned integer type uint16_t; // optional typedef unsigned integer type uint32_t; // optional typedef unsigned integer type uint64_t; // optional ..... 

和,

标题定义了所有函数,类型和宏,与C标准中的7.18相同。 [..]

然后引用C11标准,章节§7.20.1.1( 强调我的

  1. typedef名称uintN_t指定一个宽度为N且没有填充位的无符号整数类型。 因此, uint24_t表示这种无符号整数类型,其宽度恰好为24位。

  2. 这些类型是可选的。 但是,如果实现提供宽度为8,16,32或64位的整数类型,没有填充位,并且(对于具有二进制补码表示的有符号类型),它应定义相应的typedef名称。

所以,在这里我们注意到两件事。

  1. 实现不是强制要求为固定宽度的int提供支持。

  2. 正如我们所看到的,标准将宽度限制为64 。 在标准中再次没有规定宽度超过该宽度。 您需要检查正在使用的环境的文档。

正如其他答案所指出的,C ++标准不需要128位整数,即使存在,也不需要将其uint128_tuint128_t 。 如果您的编译器/体系结构不支持128位整数并且您需要它们,则可以使用boost来模拟它们:

http://www.boost.org/doc/libs/1_58_0/libs/multiprecision/doc/html/boost_multiprecision/tut/ints/cpp_int.html

我认为boost库会自动使用本机类型(如果可用)