Why are C++ int and long types both 4 bytes?

c++, cpu-architecture

Solution

The only things guaranteed about integer types are:

- `sizeof(char) == 1`

- `sizeof(char) <= sizeof(short)`

- `sizeof(short) <= sizeof(int)`

- `sizeof(int) <= sizeof(long)`

- `sizeof(long) <= sizeof(long long)`

- `sizeof(char) * CHAR_BIT >= 8`

- `sizeof(short) * CHAR_BIT >= 16`

- `sizeof(int) * CHAR_BIT >= 16`

- `sizeof(long) * CHAR_BIT >= 32`

- `sizeof(long long) * CHAR_BIT >= 64`

The other things are implementation defined. Thanks to (4), both `long` and `int` can have the same size, but it must be at least 32 bits (thanks to (9)).

Problem

Many sources, including Microsoft, reference both the int and long type as being 4 bytes and having a range of (signed) -2,147,483,648 to 2,147,483,647. What is the point of having a long primitive type if it doesn't actually provide a larger range of values?

Original source

Related problems