Is there an integer type with the same size as pointer? Guaranteed on all microarchitectures?
The C99 standard defines standard int types:
7.18.1.4 Integer types capable of holding object pointers The following type designates a signed 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:
intptr_tThe following type designates 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:
uintptr_tThese types are optional.
C99 also defines size_t and ptrdiff_t:
The types are
ptrdiff_twhich is the signed integer type of the result of subtracting two pointers;
size_twhich is the unsigned integer type of the result of the sizeof operator; and
The architectures I've seen have the maximum size of an object equal to the whole memory, so sizeof(size_t) == sizeof(void*), but I'm not aware of anything that is both portable to C89 ( which size_t is ) and guaranteed to be large enough ( which uintptr_t is ).