Out of curiosity, does anyone here know any architectures where void* -> size_t -> void* round-trips genuinely cannot work? The only example I can think of is 16-bit x86 with far pointers.
Looking at the
C standard section 7.22.1.4, it explicitly allows to cast pointers into type intptr_t/uintptr_t and back, as long as the value is not changed in between.
It should be noted that this guarantee is solely given for these types, not for size_t or other int types, and also that the conversion to pointer is not guaranteed to work if you modify the pointer in between. All of that is undefined behavior.
So you are allowed to use (u)intptr_t to store pointer values, but you are not allowed to modify them or to use another int type to do so. At least according to the standard. If you need to do this, you must check the compiler manual for the target architecture if this is allowed.
But your explicit question, if you replace size_t with intptr_t, then the answer is: This is always allowed.