Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 729
sj755 Avatar asked Sep 02 '11 05:09

sj755


1 Answers

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.

like image 187
Mysticial Avatar answered Sep 21 '22 05:09

Mysticial