我正在将一些代码从 C 移植到 C++。在我遇到的转换过程中:
uint128_t
does not name a type
我的编译器:gcc 5.2.1版
我的操作系统:Ubuntu 15.1
这编译得很好,我认为它可以通过包含 stdint.h
来解决,但事实并非如此。到目前为止,我还没有尝试任何其他方法,因为似乎没有很多关于此错误的信息( example )。 uint128_t
在整个程序中使用并且对于构建至关重要,因此我无法删除它,并且我不确定是否使用不同的整数类型。
以下是使用地点和方式的示例。
union {
uint16_t u16;
uint32_t u32;
uint128_t u128;
} value;
是否可以定义一个 uint128_t
或者我应该查看我的编译器?
最佳答案
GCC 内置了对 __int128
, unsigned __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)));
引用 documentation :
TImode
“Tetra Integer” (?) mode represents a sixteen-byte integer.
十六字节 = 16 * CHAR_BIT >= 128。
关于c++ - uint128_t 没有命名类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34588650/