Uint128_t does not name type

I am porting code from C to C ++. During the conversion, I encountered:

uint128_t does not indicate type

My compiler: gcc version 5.2.1
My operating system: Ubuntu 15.1

This compiled as C, and I thought it would be resolved by including stdint.h , but it is not. So far I have not tried anything else, since there seems to be not much information about this error ( example ). uint128_t used throughout this program and is important for the build, so I cannot remove it, and I'm not sure about using another integer type.

The following is an example of where and how it is used.

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

Is it possible to determine uint128_t or see my compiler?

+8
c ++ c types integer
source share
3 answers

GCC has built-in support for the __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))); 

Indication of documentation :

TImode

Tetra Integer (?) Mode is a sixteen byte integer.

Sixteen bytes = 16 * CHAR_BIT> = 128.

+11
source share

I thought this would be allowed by the inclusion of stdint.h , but it is not.

Well, maybe not.

First, to check the C ++ header, cstdint , from C ++ 14, chapter ยง 18.4.1,

 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 ..... 

and,

The header defines all functions, types and macros in the same way as 7.18 in the C standard. [..]

Then indicate the standard C11 , chapter ยง7.20.1.1 (emphasis mine)

  1. The name typedef uintN_t denotes an unsigned integer type with a width of N and no fill bits. Thus, uint24_t denotes such an unsigned integer type with a width of exactly 24 bits.

  2. These types are optional. However, if the implementation provides integer types with a width of 8, 16, 32, or 64 bits, without padding bits and (for signed types) that have 2), it must determine the corresponding typedef names.

So here we notice two things.

  • An implementation is not required to provide fixed-width support for int s.

  • The standard limits the width to 64 , as we see it. having a width greater than once again not authorized in the standard. You need to check the documentation of your environment.

+2
source share

As indicated in another answer, the C ++ standard does not require a 128-bit integer, as well as typedef ed like uint128_t , even if it is present. If your compiler / architecture does not support 128-bit integers, and you need them, you can use boost to simulate:

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

I think boost library will automatically use its own type, if available

0
source share

All Articles