I understand that the standard says that the size of a long integer is implementation dependant, but I am not sure why.
All it needs to do is to be able to store -2147483647 to 2147483647 or 0 to 4294967295.
Assuming that 1 byte is 8 bits, this should never need more than 4 bytes. Is it safe to say, then, that a long integer will take more than 4 bytes only if a byte has less than 8 bits? Or could there be other possibilities as well? Like maybe inefficient implementations wasting space?
The extra bytes aren’t a waste of space. A larger range is quite useful. The standard specifies minimum ranges, not the precise range itself; there’s nothing wrong with having wider types.
When the standard originally specified an
intshould be at least 16 bits, common processors had registers no larger than that. Representing alongtook two registers and special operations!But then 32 bits became the norm, and now
ints are 32 bits everywhere andlongs are 64. Nowadays most processors have 64-bit instructions, and alongcan often be stored in a single register.