Zimano Zimano - 2 months ago 35
C Question

uint128_t does not name a type

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

First and foremost; this compiled fine as C.
I thought this 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 any other information on this error (for example).
uint128_t
is used throughout the entire program and is essential for the build, therefore I can not remove it, or use a different integer type.

The code that sparks the error is widespread, for example:

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


Is there any way to either define
uint128_t
or update my compiler to handle it correctly?

Answer

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.

Comments