With C99 (and later standards) standard requires certain types to be available in the header <stdint.h>
. For exact-width, e.g., int8_t
, int16_t
, etc..., they are optional and motivated in the standard why that is.
But for the uintptr_t
and intptr_t
type, they are also optional but I don't see a reason for them being optional instead of required.
uintptr_t is an unsigned integer type that is capable of storing a data pointer (whether it can hold a function pointer is unspecified).
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. Use of uintptr_t for casting is usually safer than intptr_t , especially for comparisons.
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.
On some platforms pointer types have much larger size than any integral type. I believe an example of such as platform would be IBM AS/400 with virtual instruction set defining all pointers as 128-bit. A more recent example of such platform would be Elbrus. It uses 128-bit pointers which are HW descriptors rather than normal addresses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With