string format for intptr_t and uintptr_t

Solution 1:

That would be the following macros from inttypes.h:

For printf: PRIdPTR PRIiPTR PRIoPTR PRIuPTR PRIxPTR PRIXPTR

For scanf: SCNdPTR SCNiPTR SCNoPTR SCNuPTR SCNxPTR

Usage example:

uintptr_t p = SOME_VALUE;
printf("Here's a pointer for you: %" PRIxPTR "\n", p);

Solution 2:

I think you should consider using the 'z' modifier. This will convert anything that corresponds to a size_t og ssize_t, and I have found that it works with (u)intptr_t as well.

For example:

intptr_t ip = ...; printf("ip = %zd\n", ip);