C/C++ Size of LONG Integer varies between os and architecture
This is note about the size of ""long" integer varies between different OS and architecture. We deployed our KISS random number generator to UNIX-like system, and we found out the normalize function that "long" integer divide by max of int32 returns non unit value [0-1]. Due to the long size is 8 bytes, not 4 bytes in Windows. Here is various size of long integer between OS and architecture.
We changed data type from long integer to integer to solve this bug in the end. And a suggestion: never use "long" integer type if you want to make sure same size in varies os and arch.
OS | arch | size |
---|---|---|
Windows | IA-32 | 4 byte |
Windows | Intel® 64 or IA-64 | 4 bytes |
Linux | IA-32 | 4 bytes |
Linux | Intel® 64 or IA-64 | 8 bytes |
Mac OS X | IA-32 | 4 bytes |
Mac OS X | Intel® 64 or IA-64 | 8 bytes |
Reference: https://software.intel.com/en-us/articles/size-of-long-integer-type-on-different-architecture-and-os
沒有留言: