Given the maximum possible value, is it simple to express the space needed to write such a number in decimal form as text?
The real challenge: pid_tfixed-length registration process identifiers ( ) using gcc on Linux. It would be nice if the compilation time expression is used in iomanipulator std::setw().
I found that the linux / threads.h header contains a value PID_MAXwith the maximum pid value allocated for the process. So having
#define LENGTH(t) sizeof(#t)-1
LENGTH(PID_MAX) will be an expression of compilation time, but unfortunately this number is defined in hexa:
#define PID_MAX 0x8000
My best best solution is a little weird
static_cast<int>( ::floor( ::log(PID_MAX)/::log(10) + 1 ) );
But this is the computed runtime and uses the functions from math.h