Get bitwidth of any _BitInt(x) (especially signed)?
20:29 26 Jun 2026

So far i could only think that you can wrap an unsigned integer under -1, and use IMAX_BITS to count it. but if the macro takes in a signed _BitInt() than that wont work.

unsigned typeof(x) sadly is not allowed :( (destroys alot)

so far i have:

#include 

#define IMAX_BITS(m)                                                  \
    ((m) / ((m) % 0x3fffffffL + 1) / 0x3fffffffL % 0x3fffffffL * 30 + \
     (m) % 0x3fffffffL / ((m) % 31 + 1) / 31 % 31 * 5 + 4 -           \
     12 / ((m) % 31 + 3))

#define IS_UNSIGNED(x) ((typeof_unqual((x))) - 1 > 0)

#define BITINT_WIDTH(x) \
    (IS_UNSIGNED((x)) ? IMAX_BITS((typeof_unqual((x))) - 1) : 0)

int main() {
    unsigned _BitInt(67) a = 1;
    // prints 67
    printf("%zu\n", (size_t)(BITINT_WIDTH(a)));
}

any ideas?

c metaprogramming c23