Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is uintptr_t data type

What is uintptr_t and what can it be used for?

like image 646
dimba Avatar asked Dec 04 '09 07:12

dimba


People also ask

What is the use of Uintptr_t?

The intptr_t and uintptr_t types are extremely useful for casting pointers when you want to do address arithmetic. They should be used instead of long or unsigned long for this purpose.

Where is Uintptr_t defined in C?

It's in C99, in , as an optional type. Many C++03 compilers do provide that file. It's also in C++11, in , where again it is optional, and which refers to C99 for the definition.

What is uint32_t in C?

uint32_t is a numeric type that guarantees 32 bits. The value is unsigned, meaning that the range of values goes from 0 to 232 - 1. This. uint32_t* ptr; declares a pointer of type uint32_t* , but the pointer is uninitialized, that is, the pointer does not point to anywhere in particular.


1 Answers

First thing, at the time the question was asked, uintptr_t was 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.

In C99, it is defined as "an unsigned integer type with the property that any valid pointer to void can be converted to this type, then converted back to pointer to void, and the result will compare equal to the original pointer".

Take this to mean what it says. It doesn't say anything about size.

uintptr_t might be the same size as a void*. It might be larger. It could conceivably be smaller, although such a C++ implementation approaches perverse. For example on some hypothetical platform where void* is 32 bits, but only 24 bits of virtual address space are used, you could have a 24-bit uintptr_t which satisfies the requirement. I don't know why an implementation would do that, but the standard permits it.

like image 86
Steve Jessop Avatar answered Sep 21 '22 09:09

Steve Jessop