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

sj755 picture sj755 · Sep 2, 2011 · Viewed 22.5k times · Source

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

Answer

Mysticial picture Mysticial · Sep 2, 2011

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.