[英]Is there a reason to use std::int64_t from <cstdint>/<cinttypes> over int64_t from <stdint.h>/<inttypes.h>?
In C++11 we are provided with fixed-width integer types, such as std::int32_t
and std::int64_t
, which are defined in cstdint/cinttypes. 在C ++ 11中,我们提供了固定宽度的整数类型,例如
std::int32_t
和std::int64_t
,它们在cstdint / cinttypes中定义。 However, int32_t
and int64_t
are also in stdint.h/inttypes.h. 但是,
int32_t
和int64_t
也在stdint.h / inttypes.h中。 What are the reasons to use std::int64_t
over int64_t
? 使用
std::int64_t
不是int64_t
的原因是什么? To me, the former involves more typing, even by using namespace std
. 对我来说,前者涉及更多的输入,即使
using namespace std
。
In C++, the "C library" headers of the form <foo.h>
are deprecated, and headers <cfoo>
should be used instead. 在C ++中,不推荐使用
<foo.h>
形式的“C库”头文件,而应使用头文件<cfoo>
。 (I put "C library" in quotes because that's just a name for this part of the C++ standard library. Everything we're talking about is part of the C++ standard library, nothing has actually to do with C.) (我把“C库”放在引号中,因为这只是C ++标准库这个部分的名称。我们所讨论的一切都是C ++标准库的一部分,与C实际上没什么关系。)
Whether you should use the non-deprecated headers depends on your personal attitude towards deprecation. 是否应该使用未弃用的标题取决于您个人对弃用的态度。
(The amount of physical typing the code author has to do is a very poor concern. Code is read and maintained far more than it is written. The latter are important concerns, the former mostly a distraction.) (代码作者必须做的物理打字量是一个非常糟糕的问题。代码的读取和维护远远超过它的编写。后者是重要的问题,前者主要是分心。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.