In one of the answers (and its comments) on How to convert an int to string in C the following solution is given
char str[ENOUGH];
sprintf(str, "%d", 42);
in the comments caf mentions that ENOUGH
can be determined at compile time with:
#define ENOUGH ((CHAR_BIT * sizeof(int) - 1) / 3 + 2)
I get the + 2
because you need to be able to display the minus sign and null terminator but what is the logic behind the other part? Specifically CHAR_BIT
?