Page 1 of 1

extremely large variables in C++

Posted: Tue Jul 17, 2007 5:53 am
by AndrewAPrice
How would I define an int128/uint128 and an int256/uint256 in C++?

I'm using GCC and 32-bit x86.

Posted: Tue Jul 17, 2007 8:48 am
by os64dev
256 byte is not possible so you'll have to combine two 128 bits values. I use this but i use long mode so it might not work.

Code: Select all

typedef unsigned __uint128_t __attribute__ (( __mode__ (__TI__)));

typedef struct __uint256_t {
    __uint128_t lo, hi;
} __uint256_t;

Posted: Mon Jul 23, 2007 11:16 pm
by TomTom
But gcc doesn't fully support them. Assigning a constant (or generally speaking using them) with more than 64 bits generates compiler errors. It seems impossible to assign a 128 bit value to a 128 bit variable...

Posted: Tue Jul 24, 2007 2:43 am
by Kevin McGuire
How would I define an int128/uint128 and an int256/uint256 in C++?
In C++ you would use the power of classes and operator overloading.