What I have done sometimes in the past uses a larger data type, and then when I convert to my smaller type, immediately convert it back to a larger type and make sure the value has not changed.
For example, let's say you used int64_t instead, then you might have something like:
int64_t my_pid64; pid_t my_pid = (pid_t) my_pid64; if ((int64_t) my_pid != my_pid64) { }
There is not much opportunity to use a larger data type. "long" used to be the largest primitive data type, but this is not true for some common compilers / architectures, even Linux (see comments below). Meanwhile, the intmax_t type has poor library support. As a result, int64_t is sometimes more useful in practice.
But basically your options for a larger data type are probably long, int64_t and intmax_t.
source share