x.c
text/x-csrc
#include <stdio.h>
#define DECIMAL_DIGITS_TABLE(i) \
(i == 0 ? 9 : \
i == 1 ? 99 : \
i == 2 ? 999 : \
i == 3 ? 9999 : \
i == 4 ? 99999 : \
i == 5 ? 999999 : \
i == 6 ? 9999999 : \
i == 7 ? 99999999 : \
i == 8 ? 999999999 : 0 )
#define DECIMAL_DIGITS_FOR_BITS(bits) \
(1 + \
((9 * (bits)) >> 5) + \
(((1 << (bits)) - 1) > DECIMAL_DIGITS_TABLE((9 * (bits)) >> 5)))
#define PROCNUMBER_BITS 18
#define MAX_BACKENDS ((1 << PROCNUMBER_BITS) - 1)
#define PROCNUMBER_CHARS DECIMAL_DIGITS_FOR_BITS(PROCNUMBER_BITS)
int
main()
{
printf("PROCNUMBER_BITS = %d\n", PROCNUMBER_BITS);
printf("PROCNUMBER_CHARS = %d\n", PROCNUMBER_CHARS);
printf("MAX_BACKENDS = %x\n", MAX_BACKENDS);
for (unsigned int i = 1; i <= 32; ++i)
printf("bits = %u, max = %u, digits = %d\n",
i,
(1 << i) - 1,
DECIMAL_DIGITS_FOR_BITS(i));
}