../

Summary

I've been working on legacy code maintenance issues and dealing with some code that works around differences between 32-bit and 64-bit builds. And I was confused about the size of some types, such as int, long, and long long. So I compiled some test code to compare on different systems.

Turns out, the operating system is what makes the biggest difference in terms of compatibility across systems, not the hardware. On Windows, going between 32-bit and 64-bit makes little difference. Types such as long are the same. While on Linux and Mac, going from 32-bit to 64-bit means that long increases from 4 bytes to 8 bytes.

But definitely the biggest surprise was long double, which goes from 8 bytes, to 12 bytes, and finally 16 bytes.

(Don't get me started on the fact that int and long are identical on 32-bit systems! And 64-bit Windows... <sigh>)

32-bit and 64-bit types

See the table for the results from a trivial C++ application built on some common 32-bit and 64-bit systems:

  ARM 32-bit Linux
g++ 4.9
ARM 64-bit Linux
g++ 7.5.0
x86 32-bit Linux
g++ 4.8
x64 64-bit Linux
g++ 5.4
x86 32-bit Windows 7
VisualStudio 2013
x64 64-bit Windows 7
VisualStudio 2013
x64 64-bit MacOS 10.15
clang 11.0.0
sizeof(bool) 1 1 1 1 1 1 1
sizeof(char) 1 1 1 1 1 1 1
sizeof(short) 2 2 2 2 2 2 2
sizeof(int) 4 4 4 4 4 4 4
sizeof(long) 4 8 4 8 4 4 8
sizeof(long long) 8 8 8 8 8 8 8
sizeof(float) 4 4 4 4 4 4 4
sizeof(double) 8 8 8 8 8 8 8
sizeof(long double) 8 16 12 16 8 8 16
sizeof(size_t) 4 8 4 8 4 8 8
sizeof(void *) 4 8 4 8 4 8 8
sizeof(DWORD) n/a n/a n/a n/a 4 4 n/a
Where the values are the number of bytes each type requires.
Last modified: 2020-05-11
Stéphane Charette, stephanecharette@gmail.com
../