I am writing a program to store data to a file on the unit of every 32 bits (i.e. 4 bytes at a time). I wrote the code in 64-bit windows system but the compiler I used is 32 bits (mingw32). In the current system, the size of int an long are the same, 32 bits (4bytes). I am current porting the code to other systems by recompiling with g++ (without changing the code). However, I found that the size of int or long are different and depending on the system. Is that any way (like using a macro in the header file) to determine the size of an integer so to decide if int or long should be used as the data type in the code? I have to recompile the code in 4 different type of system, it is really a headache if I modify the code to have 4 different copies for each system.
Share
What you want to do is use the standard types like
int32_t. This type is always 32 bits. I currently use these types in a portable database (berkeley db) for cross-system compatibility.See here for all of them.
Include stdint.h to get these definitions.