The types short , int , long and long long do not have a standard size. As a rule, their size is determined based on the processor architecture. For example, on x86 long - 4 bytes, on x86_64 - 8 bytes.
There is another important feature in the definition of these types. C and C ++ languages were created to work on as many platforms as possible. Some platforms do not support memory without alignment to the size of the machine word . The long type is the standard type of machine word in C and C ++. On such platforms, the memory address should always be a multiple of sizeof(long) , and most often, it is this minimum byte that we can read from memory at a time.
Although x86 and followers support unaligned memory access, aligned access is usually still faster, so similar long notation is still important.
To save people from contradictions, fixed-size types were introduced, for example, int32_t , uint8_t , int64_t . In most cases, when writing portable programs, the priority of using types should be:
Special types ( size_t , off_t ). We apply where they semantically express the essence of variables.
Types with a fixed size. So we avoid different problems when compiling 32 and 64 bits, especially when working with files and the network.
We use classical types ( int , short , long ) for platform-specific optimizations, and remember that the size may change on a different platform.
typeof. - αλεχολυτ