Would making plain int 64-bit break a lot of reasonable code?

后端 未结 8 2089
独厮守ぢ
独厮守ぢ 2021-02-19 03:12

Until recently, I\'d considered the decision by most systems implementors/vendors to keep plain int 32-bit even on 64-bit machines a sort of expedient wart. With mo

8条回答
  •  情书的邮戳
    2021-02-19 04:06

    With modern C99 fixed-size types (int32_t and uint32_t, etc.) the need for there to be a standard integer type of each size 8, 16, 32, and 64 mostly disappears,

    C99 has fixed-sized typeDEFs, not fixed-size types. The native C integer types are still char, short, int, long, and long long. They are still relevant.

    The problem with ILP64 is that it has a great mismatch between C types and C99 typedefs.

    • int8_t = char
    • int16_t = short
    • int32_t = nonstandard type
    • int64_t = int, long, or long long

    From 64-Bit Programming Models: Why LP64?:

    Unfortunately, the ILP64 model does not provide a natural way to describe 32-bit data types, and must resort to non-portable constructs such as __int32 to describe such types. This is likely to cause practical problems in producing code which can run on both 32 and 64 bit platforms without #ifdef constructions. It has been possible to port large quantities of code to LP64 models without the need to make such changes, while maintaining the investment made in data sets, even in cases where the typing information was not made externally visible by the application.

提交回复
热议问题