1

When CLang 14 was released I noticed that following code doesn't compile anymore (but works in CLang 13):

Try it online!

int main() { using T = _ExtInt(256); }

This code was used to create fixed size integers of arbitrary bit length, even of unusual bit sizes like _ExtInt(12345). And everything worked for any bit size.

In CLang 14 you can use only 128 bits:

Try it online!

int main() { using T = _ExtInt(128); }

Above code works in both CLang 13 and 14, but says _ExtInt() is deprecated and suggest to use _BitInt(128) instead.

Of course there exists unsigned __int128, but _ExtInt()/_BitInt() can be used to create any bit size including prime numbers like _ExtInt(97)/_BitInt(97) (online).

I have two questions:

  1. Is there any chance in CLang 14 to have (natively) integers bigger than 128 bits? Of course external libraries like Boost can provide them. But what about native support? As CLang 13 natively supported any weird bit size like _ExtInt(12345).

  2. Is _BitInt(x) exactly same as _ExtInt(x) in CLang 14 for any x?

phuclv
  • 37,963
  • 15
  • 156
  • 475
Arty
  • 14,883
  • 6
  • 36
  • 69
  • 3
    From https://clang.llvm.org/docs/LanguageExtensions.html#extended-integer-types "Clang supports the C23 _BitInt(N) feature as an extension in older C modes and in C++. This type was previously implemented in Clang with the same semantics, but spelled _ExtInt(N). This spelling has been deprecated in favor of the standard type." – Retired Ninja Aug 27 '22 at 06:45
  • Worth noting that `__BITINT_MAXWIDTH__` is `128` in clang 14 (which says only `_BitInt(2)` through `_BitInt(128)` is supported (In C23, `#define BITINT_MAXWIDTH __BITINT_MAXWIDTH__` is used) – Artyer Aug 27 '22 at 14:44
  • N.B. It's "Clang" like the English word, not "CLang" like "see lang". – Jonathan Wakely Oct 26 '22 at 08:30
  • @JonathanWakely For me it was almost obvious that CLang word comes from C + Language, meaning that it supports C/C++ and it is language. Sure it became like English word now so can be written Clang, but still origin of this word for me looks obvious. – Arty Oct 26 '22 at 16:38

1 Answers1

3

From https://releases.llvm.org/14.0.0/tools/clang/docs/ReleaseNotes.html#c-language-changes-in-clang:

Currently, Clang supports bit widths <= 128 because backends are not yet able to cope with some math operations (like division) on wider integer types. See PR44994 for more information.

And

_BitInt(N) and _ExtInt(N) are the same types in all respects beyond spelling and the deprecation warning.

Note that while Clang 13 allows _ExtInt(256), it crashes as soon as a _ExtInt(256) value is divided by 3 (or basically any other value that's not statically a power of 2). (live)

cpplearner
  • 13,776
  • 2
  • 47
  • 72
  • BTW, as I remember division works only till 128 bits. But any other generic operation works for any bigger bit size, i.e. you can add/sub/mul/xor/shift/and/or/not any size like `_ExtInt(12345)`. – Arty Aug 27 '22 at 14:19