int_least64_t vs int_fast64_t vs int64_t

后端 未结 2 1444
青春惊慌失措
青春惊慌失措 2020-12-08 18:50

I\'m trying to port my code to 64bit.

I found that C++ provides 64bit integer types, but I\'m still confused about it.

First, I found four different 64bit

相关标签:
2条回答
  • 2020-12-08 19:33

    On your platform, they're all names for the same underlying data type. On other platforms, they aren't.

    int64_t is required to be EXACTLY 64 bits. On architectures with (for example) a 9-bit byte, it won't be available at all.

    int_least64_t is the smallest data type with at least 64 bits. If int64_t is available, it will be used. But (for example) with a 9-bit byte machine, this could be 72 bits.

    int_fast64_t is the data type with at least 64 bits and the best arithmetic performance. It's there mainly for consistency with int_fast8_t and int_fast16_t, which on many machines will be 32 bits, not 8 or 16. In a few more years, there might be an architecture where 128-bit math is faster than 64-bit, but I don't think any exists today.


    If you're porting an algorithm, you probably want to be using int_fast32_t, since it will hold any value your old 32-bit code can handle, but will be 64-bit if that's faster. If you're converting pointers to integers (why?) then use intptr_t.

    0 讨论(0)
  • 2020-12-08 19:39

    int64_t has exactly 64 bits. It might not be defined for all platforms.

    int_least64_t is the smallest type with at least 64 bits.

    int_fast64_t is the type that's fastest to process, with at least 64 bits.

    On a 32 or 64-bit processor, they will all be defined, and will all have 64 bits. On a hypothetical 73-bit processor, int64_t won't be defined (since there is no type with exactly 64 bits), and the others will have 73 bits.

    0 讨论(0)
提交回复
热议问题