c32bit-64bitlong-integerbitlong-long

Why do C compilers specify long to be 32-bit and long long to be 64-bit?


Wouldn't it have made more sense to make long 64-bit and reserve long long until 128-bit numbers become a reality?


Solution

  • Yes, it does make sense, but Microsoft had their own reasons for defining "long" as 32-bits.

    As far as I know, of all the mainstream systems right now, Windows is the only OS where "long" is 32-bits. On Unix and Linux, it's 64-bit.

    All compilers for Windows will compile "long" to 32-bits on Windows to maintain compatibility with Microsoft.

    For this reason, I avoid using "int" and "long". Occasionally I'll use "int" for error codes and booleans (in C), but I never use them for any code that is dependent on the size of the type.