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.

Share:
20,024
WilliamKF
Author by

WilliamKF

Updated on November 23, 2020

Comments

  • WilliamKF
    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
    Drew Dormann almost 12 years
    That header exists for backwards-compatibility with C. It will define uintptr_t in the global namespace, but not namespace std. You can expect all standard headers that end in .h to be namespace-unaware.
  • WilliamKF
    WilliamKF almost 12 years
    Thanks Drew, I had missed that.
  • Pete Becker
    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 into namespace std and are now allowed to put them in the global namespace, as well (that's a bow to existing implementations).
  • Pete Becker
    Pete Becker almost 12 years
    <cinttypes> doesn't define uintptr_t. Mostly it defined macros that can be used as format specifiers for the types defined in <cstdint> when using printf and scanf and their brethren.
  • obataku
    obataku almost 12 years
    @PeteBecker <cinttypes> includes <cstdint>