關於 web service, unity, blogger 等軟體工程筆記

C/C++ Size of LONG Integer varies between os and architecture

Edit icon 沒有留言
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.

OSarchsize
WindowsIA-324 byte
WindowsIntel® 64 or IA-644 bytes
LinuxIA-324 bytes
LinuxIntel® 64 or IA-648 bytes
Mac OS XIA-324 bytes
Mac OS XIntel® 64 or IA-648 bytes

Reference: https://software.intel.com/en-us/articles/size-of-long-integer-type-on-different-architecture-and-os

沒有留言: