use of 128 bit unsigned int in c language

2.1k Views Asked by At

I need to use a 128 bit unsigned int variable in my code.
Searching on line I read about unsigned __int128. Here https://gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html I read

type __int128 is supported for targets which have an integer mode wide enough to hold 128 bits

My first question is what does it means with target? what I have to check to see if my pc can express such type?
The second question is how to print such kind of variable?
Lastly do I need to do something to use this kind of variables? The same above link says

Simply write __int128 for a signed 128-bit integer, or unsigned __int128 for an unsigned 128-bit integer.

So it seems I don't need to #include anything and I even don't add some option in gcc during the compiolation, is it right?

1

There are 1 best solutions below

1
On BEST ANSWER
  1. "Target" means the specific combination of CPU architecture and operating system that your compiler is configured to create programs for. There is a discussion at Does a list of all known target triplets in use exist?. But "integer mode" is really a concept used internally by the compiler, and only indirectly related to what the hardware can and can't do. So all this really says is "the compiler supports 128-bit integers on some targets and not on others". The easiest way to find out whether yours does is to just try to compile and run a small test program that uses __int128.

  2. Most system's printf functions don't support __int128, so you have to write your own code to print them, or find third-party code somewhere. See How to print __int128 in g++? which is for C++ but still relevant.

  3. You don't need to include anything or use any special options.