C print pointers correctly

What’s the proper use of printf to display pointers padded with 0s

#include <inttypes.h>
#include <stdint.h>

printf("0x%012" PRIxPTR "\n", (uintptr_t) ptr);

printf("%012p", ptr);
warning: '0' flag used with ‘%p’ gnu_printf format [-Wformat]

printf("0x%012X", ptr);
warning: format ‘%X’ expects argument of type ‘unsigned int’, but argument 3 has type ‘XXX’ [-Wformat]

Leave a Reply

Your email address will not be published. Required fields are marked *