Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the header file for the uintptr_t type in modern C++?

Tags:

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?

like image 551
WilliamKF Avatar asked Sep 01 '12 13:09

WilliamKF


People also ask

What is Uintptr_t in C?

uintptr_t is an unsigned integer type that is capable of storing a data pointer (whether it can hold a function pointer is unspecified). Which typically means that it's the same size as a pointer. It is optionally defined in C++11 and later standards.

What is intptr_t type?

intptr_t is a signed integer memsize-type that can safely store a pointer regardless of the platform capacity. The type intptr_t is similar to the types ptrdiff_t and INT_PTR. The size of the type depends upon the data model.

What is uintptr_t?

It's an unsigned integer type exactly the size of a pointer. Whenever you need to do something unusual with a pointer - like for example invert all bits (don't ask why) you cast it to uintptr_tand manipulate it as a usual integer number, then cast back.

Is uintptr_t a namespace aware header?

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. Thanks Drew, I had missed that. @DrewDormann - they aren't necessarily unaware of namespaces.

Should cbindgen include inttypes in headers?

} Cbindgen should itself include inttypes.h (and all other relevant types) for allow C language emitted headers to work. Hmmm, which c compiler / library are you using?

Where can I find uintptr_TWAS in C++?

5 Answers 5 ActiveOldestVotes 274 First thing, at the time the question was asked, uintptr_twas not in C++. It's in C99, in <stdint.h>, as an optional type. Many C++03 compilers do provide that file. It's also in C++11, in <cstdint>, where again it is optional, and which refers to C99 for the definition.


2 Answers

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

like image 176
Mike Seymour Avatar answered Sep 22 '22 12:09

Mike Seymour


It is defined in stdint.h:

#include <stdint.h>
like image 25
WilliamKF Avatar answered Sep 21 '22 12:09

WilliamKF