Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a reason to use std::int64_t from <cstdint>/<cinttypes> over int64_t from <stdint.h>/<inttypes.h>?

Tags:

c++

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.

like image 446
sofname Avatar asked Oct 19 '25 12:10

sofname


1 Answers

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

like image 115
Kerrek SB Avatar answered Oct 22 '25 04:10

Kerrek SB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!