What is the header file for the uintptr_t type in modern C++?
20,024
Solution 1
In C++11, it's in <cstdint>
.
In older versions of the language, it didn't officially exist; but many compilers provided the C99 library as an extension, in which case it would be available in <stdint.h>
.
Solution 2
It is defined in stdint.h:
#include <stdint.h>
Solution 3
In C++, the standard header is in cstdint
#include <cstdint>
Solution 4
Include either cinttypes
or cstdint
.
![WilliamKF](https://i.stack.imgur.com/FkIiK.png?s=256&g=1)
Author by
WilliamKF
Updated on November 23, 2020Comments
-
WilliamKF over 3 years
I found that in C99 you should
#include <stdint.h>
and that seems to work with my C++03 gcc compiler too, but is that the right header for modern C++, is it portable? -
Drew Dormann almost 12 yearsThat header exists for backwards-compatibility with C. It will define
uintptr_t
in the global namespace, but notnamespace std
. You can expect all standard headers that end in.h
to be namespace-unaware. -
WilliamKF almost 12 yearsThanks Drew, I had missed that.
-
Pete Becker almost 12 years@DrewDormann - they aren't necessarily unaware of namespaces. The standard C headers are required to put their names in the global namespace, and they are permitted to put them in
namespace std
. Similarly, the C++ analogs of the C headers are required to put their names intonamespace std
and are now allowed to put them in the global namespace, as well (that's a bow to existing implementations). -
Pete Becker almost 12 years
<cinttypes>
doesn't defineuintptr_t
. Mostly it defined macros that can be used as format specifiers for the types defined in<cstdint>
when usingprintf
andscanf
and their brethren. -
obataku almost 12 years@PeteBecker
<cinttypes>
includes<cstdint>