I am porting some code from C to C++. During the conversion I encountered:
uint128_t
does not name a type
My compiler: gcc version 5.2.1
My operating system: Ubuntu 15.1
This compiled fine as C and I thought it would be resolved by including stdint.h
but it has not. So far I have not tried anything else since there doesn't seem to be a lot of information on this error (example). uint128_t
is used throughout this entire program and is essential for the build, therefore I can not remove it, and I'm not sure about using a different integer type.
Below is an example of where and how it is used.
union {
uint16_t u16;
uint32_t u32;
uint128_t u128;
} value;
Would it be okay to define a uint128_t
or should I look at my compiler?
Since the __uint128_t type is a GCC extension, the proper thing to do is probably to check for some known-good version of GCC. See this page for information about the macros used to version-check the GCC compiler. Follow this answer to receive notifications.
Simply write __int128 for a signed 128-bit integer, or unsigned __int128 for an unsigned 128-bit integer. There is no support in GCC for expressing an integer constant of type __int128 for targets with long long integer less than 128 bits wide.
uint32_t is a numeric type that guarantees 32 bits. The value is unsigned, meaning that the range of values goes from 0 to 232 - 1. This. uint32_t* ptr; declares a pointer of type uint32_t* , but the pointer is uninitialized, that is, the pointer does not point to anywhere in particular.
GCC has builtin support for the types __int128
, unsigned __int128
, __int128_t
and __uint128_t
(the last two are undocumented). Use them to define your own types:
typedef __int128 int128_t;
typedef unsigned __int128 uint128_t;
Alternatively, you can use __mode__(TI)
:
typedef int int128_t __attribute__((mode(TI)));
typedef unsigned int uint128_t __attribute__((mode(TI)));
Quoting the documentation:
TImode
“Tetra Integer” (?) mode represents a sixteen-byte integer.
Sixteen byte = 16 * CHAR_BIT >= 128.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With