Why do C compilers specify long to be 32-bit and long long to be 64-bit?

后端 未结 6 1791
醉酒成梦
醉酒成梦 2021-01-04 12:53

Wouldn\'t it have made more sense to make long 64-bit and reserve long long until 128-bit numbers become a reality?

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-04 13:40

    C99 N1256 standard draft

    Sizes of long and long long are implementation defined, all we know are:

    • minimum size guarantees
    • relative sizes between the types

    5.2.4.2.1 Sizes of integer types gives the minimum sizes:

    1 [...] Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown [...]

    • UCHAR_MAX 255 // 2 8 − 1
    • USHRT_MAX 65535 // 2 16 − 1
    • UINT_MAX 65535 // 2 16 − 1
    • ULONG_MAX 4294967295 // 2 32 − 1
    • ULLONG_MAX 18446744073709551615 // 2 64 − 1

    6.2.5 Types then says:

    8 For any two integer types with the same signedness and different integer conversion rank (see 6.3.1.1), the range of values of the type with smaller integer conversion rank is a subrange of the values of the other type.

    and 6.3.1.1 Boolean, characters, and integers determines the relative conversion ranks:

    1 Every integer type has an integer conversion rank defined as follows:

    • The rank of long long int shall be greater than the rank of long int, which shall be greater than the rank of int, which shall be greater than the rank of short int, which shall be greater than the rank of signed char.
    • The rank of any unsigned integer type shall equal the rank of the corresponding signed integer type, if any.
    • For all integer types T1, T2, and T3, if T1 has greater rank than T2 and T2 has greater rank than T3, then T1 has greater rank than T3

提交回复
热议问题