1

What prevents C++ standard from having a 128/256 bit integer?

From other stackoverflow questions, recommendation to achieve this are Boost or compiler extension __int128 or std::bitset<>

So it is obvious that programmers are using/needing this. Why is there a reluctance in adopting it?

7
  • 1
    just because something exists in boost is not a proof that it is needed... Commented Aug 18, 2021 at 19:15
  • 3
    There is definitely a need for it, but not for very many programs. And support for bigger int sizes exists, for example, clang's _ExtInt supports integers with bitwidth of 1 all the way to a whopping 16,777,215. Even though there is no std::uint16777215_t. Alas. Sad panda. Commented Aug 18, 2021 at 19:18
  • 1
    "'What prevents C++ standard from having a 128/256 bit integer?" --> Nothing prevents it other than history and lack of necessity. Perhaps in the future. Commented Aug 18, 2021 at 19:22
  • @DrewDormann: In our programs we started encountering 128 bits expectation from customer side. Commented Aug 18, 2021 at 19:23
  • 1
    There has to be a cutoff at some point at the language level. Eventually, you might as well just have a APInt<std::size_t> in the standard library instead and let compilers specialize it for sizes where hardware support is available. Commented Aug 18, 2021 at 19:42

1 Answer 1

3

The reason is expense and lack of need. If the standard required a 128-bit integer type, every compiler would have to implement it. On hardware that doesn't support such an integer type natively, implementations would have to provide a way of generating code to emulate it. There simply aren't enough folks who need such a type to justify imposing it on every compiler.

Sign up to request clarification or add additional context in comments.

12 Comments

With my very little knowledge in instruction set, why can't we have two 64bit registers to achieve this(if no 128 bit register)? What's the difficulty in it?
The de-facto "floor" of C++ in terms of type bitness is 16bit... which reasonably speaking means that is also the de-facto floor for hardware C++ supports. Now imagine implementing 128bit multiply on 16 bit hardware. 😱
@Mgetz: If your statement is true it makes sense :)
@InQusitive in theory you can implement C++ for the 6502... but is it worth it probably not. But C++ very much exists in 16bit hardware.
@InQusitive -- 128-bit integers are certainly implementable on pretty much any sane hardware. That's not the issue. The question is whether it's worthwhile to require every compiler implementor to put in the time and effort needed to implement and test it. Even on 8-bit processors. <g>
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.