C language > Expert questions

Pointers as numeric identifiers

(1/1)

PaoloC13:
Wanting to use pointers as unique numeric identifiers of single data objects, what kind of data type do you suggest to correctly contain the numeric value of a pointer?
Now I'm going to use size_t. Is size_t always the same size of a pointer?
Is there a more appropriate choice?

algernon_77:
Hello,

Pointers are 32 bit on a x86 app and 64 bit on a x64 app, so I would use UINT_PTR data type to hold a pointer.
size_t is basically the type that sizeof operator returns and, as I remember, it used to be guaranteed to be at least 16 bits. I don't know what is its maximum size on modern compilers.

Pelle:
intptr_t (signed) or uintptr_t (unsigned) from <stdint.h> seems like the best choice.

PaoloC13:
Yes, I will use uintptr_t
Thank you all

algernon_77:
Definitely a better choice, since there's no need to include all MS galore just for UINT_PTR/INT_PTR types.
A big thanks from me, too  :) !

Navigation

[0] Message Index

Go to full version