是英寸长"还是用C有用吗? [英] Is "long" still useful in C?

查看:111
本文介绍了是英寸长"还是用C有用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 这不是最大的整数,现在还有很长很长型了。

  • 这不是一个固定宽度型:这是在一些平台上32位和64他人

  • 这是不一定的大小作为指针相同(例如,在64位的Windows)

因此​​,没有长有任何意义了吗?是否有过一个理由来声明一个长期而不是ptrdiff_t的或的int64_t?

So, does "long" have any meaning anymore? Is there ever a reason to declare a long instead of a ptrdiff_t or int64_t?

推荐答案

仍然有用你应该习惯性地使用之间的细微差别。在键入依然蓬勃发展,为的克里斯·卢茨指出落后于许多系统和平台特定类型的(虽然,通常为无符号)。

There's a subtle difference between still useful and something you should habitually use. The long type still thrives, as Chris Lutz noted behind many system and platform specific types (though, usually as unsigned).

知道的你会总是要适应这类型的工作数据(愉快,更好,如果你还知道的符号性),没有特别的理由的的使用,特别是如果你有一个结构,空间有限的工作。

When you know the data you will be working with is always going to fit in that type (agreeably, better if you also know the signedness), there is no particular reason not to use it, especially if you have limited space in a structure to work with.

然而,在大多数情况下,为将来的维护的缘故,其最好使用intxx_t或uintxx_t尽可能。例如,你的的知道,一个UNIX纪元日期将始终放不下了一个unsigned long在32位平台上(因此,time_t的),除非你有充分根据,世界将之前结束它翻转:)

However, in most cases, for the sake of future maintainers, its much better to use intxx_t or uintxx_t wherever possible. For instance, you don't know that a UNIX epoch date will always fit inside an unsigned long on 32 bit platforms (hence, time_t), unless you have it on good authority that the world will end before it rolls over :)

这篇关于是英寸长"还是用C有用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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