int_least64_t 与 int_fast64_t 与 int64_t [英] int_least64_t vs int_fast64_t vs int64_t

查看:61
本文介绍了int_least64_t 与 int_fast64_t 与 int64_t的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的代码移植到 64 位.

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

我发现 C++ 提供了 64 位整数类型,但我仍然对此感到困惑.

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

首先,我找到了四种不同的 64bit ints:

First, I found four different 64bit ints:

int_least64_t
int_fast64_t
int64_t
intmax_t

和它们未签名的对应物.我使用 sizeof() 测试了它们,它们是 8 字节,所以它们是 64 位.

and their unsigned counterparts. I tested them using sizeof() and they are 8 byte so they are 64bit.

它们之间有什么不同?leastfast 类型的含义是什么?intmax_t 怎么样?

What's the different between them? What is the meaning of the least and fast types? What about intmax_t?

推荐答案

在您的平台上,它们都是相同基础数据类型的名称.在其他平台上,它们不是.

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

int64_t 必须为 64 位.在(例如)具有 9 位字节的体系结构上,它根本不可用.

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 是至少 64 位的最小数据类型.如果 int64_t 可用,它将被使用.但是(例如)对于 9 位字节的机器,这可能是 72 位.

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 是至少 64 位且算术性能最好的数据类型.它的存在主要是为了与 int_fast8_tint_fast16_t 保持一致,它们在许多机器上将是 32 位,而不是 8 位或 16 位.再过几年,可能会有一个架构128 位数学比 64 位更快,但我认为今天不存在.

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.

如果您要移植算法,您可能希望使用 int_fast32_t,因为它会保存您的旧 32 位代码可以处理的任何值,但如果速度更快,它将是 64 位.如果您要将指针转换为整数(为什么?),请使用 intptr_t.

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.

这篇关于int_least64_t 与 int_fast64_t 与 int64_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆