Why integer stayed 4 bytes long when world transitioned to 64 bits?

I did some research on this topic and I decided to share my findings.

First reason: Standards

On most 32 bits systems type short is 2 bytes long, type int is 4 bytes long. But there are also standards.

According to C90 standard:

sizeof(short) <= sizeof(int) <= sizeof(long)

According to C99 standard:

sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)

If int size will 8 bytes long then there will be no type that it is 4 bytes long because due to standard, long type should be at least the same size as int type. It is possible to make short type 4 bytes long but then there will no type that is 2 bytes long. Technically we can use wchar_t type as 2 bytes integer but it will look a bit strange as this type is mostly used for processing characters.

Second reason: Problems

There are millions of data structures that has int data type in them. And a lot of these data structures are used to read and write to and from disk, network, and other type of I/O. If size of int type changes, then a lot of code will stop working after recompilation of source code to 64 bits. Eventually code will be fixed but it will require enormous effort and it will considerably slowdown migration to 64 bits or even put it on hold. After all, nobody wants buggy software.

Third reason: Practical

Moreover, in many cases it is not even practical to have int type longer than 4 bytes. Imagine following structure:

struct SomeType
{
    int first;
    int second;
};

If int type will be 8 bytes long, then size of this structure will be doubled without any other benefits. Most code is not ready to process huge data structure anyway and requires a lot of changes to do so.

Fourth reason: shorter

And lastly, there is no disadvantages. When world was moving from 16 bites to 32 bits, int type size changed from 2 bytes to 4 bytes. And one of the reasons for this change was that instruction that adds some value to 2 bytes integer is 1 byte longer in 32 bits than instruction to add some value to 4 bytes integer. In 64 bits it stays the same and instruction to add some value to 8 bytes integer also requires one more byte. As result, code that manipulates integers is shorter and often faster because more code will fit in processor cache.

These are all reason I found to why int type stays 4 bytes. I hope it helps someone

Comments

Post comment