简体   繁体   中英

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. However, int32_t and int64_t are also in stdint.h/inttypes.h. What are the reasons to use std::int64_t over int64_t ? To me, the former involves more typing, even by using namespace std .

In C++, the "C library" headers of the form <foo.h> are deprecated, and headers <cfoo> should be used instead. (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.)

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM