I need to store an array of items, where each item is 32 bits in length. So currently I'm using an array of long
. However I'm compiling on another machine now where a long
is 64 bits. This creates problems when it comes to signed numbers. (i.e. printing the same number on both machines, one will be negative (32-bit) and the other will be positive (64-bit).
So the plan is to switch to int32_t
, the problem is that when using format strings to print the numbers out, the specifiers need to different as on the 32-bit machine int32_t
is defined as a long
and on the 64-bit machine it's defined as an int
.
What is the best way to make sure that it will be 32-bits on whatever machine it's compiled on, and that the number can be printed? It seems like this is a lot of hassle and that there should be a simpler/easier way to have an array of items 32-bits in length.