I'm trying to compile this on my Raspberry Pi

int main()
    __int128 a = 0;
    return 1;

and I get this error

pi@raspberrypi ~ $ g++-4.7 main.cpp 
main.cpp: In function ‘int main()’:
main.cpp:3:2: error: expected primary-expression before ‘__int128’
main.cpp:3:2: error: expected ‘;’ before ‘__int128’

This works fine on another machine.

I'm assuming this is because the pi doesn't have hardware support for 128bit ints but I couldn't find much information regarding this. This functionality is crucial for my project so I thought I'd check first.

  • Out of sheer curiosity, why on earth do you need 128-bit integers? – fouric Dec 17 '12 at 1:47
  • @InkBlend I'm emulating a computer that uses 77bit ints – Adam Dec 17 '12 at 9:16
  • I am completely baffled. What kind of crazy computer uses 77-bit ints? – fouric Dec 19 '12 at 20:56
  • 1
    @InkBlend The Ferranti Pegasus uses 39 bit words and contains a double length accumulator which can hold a 39bit int multiplied by a 39bit int giving a 77bit int. Arithmetic operations can then be done with this 77bit int. – Adam Dec 20 '12 at 8:41

__int128 is not part of the standard. Even if a compiler supports it, it's bad style to use it directly that way. Identifiers starting with two underscores, or an underscore and an uppercase letter, are by definition reserved for the compiler / library, i.e. the identifier alone tells you "back off, dude, this is not for you".

In the header <cinttypes> you will find the types intmax_t and uintmax_t, which - also by definition - represent the largest integers a compiler will support. If these are smaller than 128 bit (sizeof( intmax_t ) < 16), then that is too bad, and you cannot do much about it. (You might even find int128_t and uint128_t in <cstdint>. Cannot find my copy of the C standard right now whether a platform supporting 128-bit integers is actually required to provide those two.)

Having your project depend on the existence of a native 128-bit integer is bad design anyway if you are aiming for portability (to a RaspPi, for example), as most platforms are bound to not support those natively. So, you should probably test for the width of intmax_t as described above, and keep an alternative implementation ready that relies on third-party arbitrary precision arithmetics. BjB already mentioned GMP. There's also TTMath, and probably others.

  • 1
    I was aware that __int128 is not part of the standard. As far as i can see <cstdint> (which i use for int64_t) does not include any 128 bit ints. I am aiming for portability so i will have to either use a big int library or implement my own functions (or recode in python). I was just curious as to whether the pi has hardware support for 128bit ints. I guess not. – Adam Dec 11 '12 at 19:41

I have not tried, but you could try to compile and use this library on the pi. I quote:

GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating point numbers. There is no practical limit to the precision except the ones implied by the available memory in the machine GMP runs on.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.