Why "long int" has same size as "int"? Does this modifier works at all?

All that the standard requires is that:

sizeof(char) == 1

and

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

(and that the corresponding unsigned types have the same size as the signed types).

In addition, there are minimum sizes for each type, indirectly specified by limits on the values of INT_MAX, etc.: a char must be at least 8 bits, a short and an int 16, a long 32 and a long long 64.

On 16 bit platforms, it is usual for both short and int to be 16 bits; on 32 bit platforms (and the 36 and 48 bit platforms that still exist), int and long are almost always the same size. On modern 64 bit platforms (with byte addressing), the rational solution would be to make all four types have different sizes (although one could argue that according to the standard, int should be 64 bits, which would mean that int, long and long long all had the same size).


The reason that MS choose to makelong 32 bits even on a 64-bit system is that the existing Windows API, for historical reasons use a mixture of int and long for similar things, and the expectation is that this is s 32-bit value (some of this goes back to times when Windows was a 16-bit system). So to make the conversion of old code to the new 64-bit architecture, they choose to keep long at 32 bits, so that applications mixing int and long in various places would still compile.

There is nothing in the C++ standard that dictates that a long should be bigger than int (it certainly isn't on most 32-bit systems). All the standard says is that the size of short <= int <= long - and that short is at least 16 bits, if memory serves [not necessarily expressed as "should be at least 16 bits", I think it mentions the range of values].


C and C++ implementations, a long is larger or equal to an int. Today's most popular desktop platforms, such as Windows and Linux, run primarily on 32 bit processors and most compilers for these platforms use a 32 bit int which has the same size and representation as a long.