Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uint128_t does not name a type

Tags:

c++

c

types

integer

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?

like image 499
Zimano Avatar asked Jan 04 '16 10:01

Zimano


People also ask

What is __ uint128_t?

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.

How do you write a 128-bit integer?

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.

What is uint32_t in C?

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.


1 Answers

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.

like image 60
Andrea Corbellini Avatar answered Sep 28 '22 07:09

Andrea Corbellini