In C, I\'d like to use printf to display pointers, and so that they line up properly, I\'d like to pad them with 0s.
My guess was that the proper way to do this was:
As your link suggests already, the behaviour is undefined. I don't think there's a portable way of doing this as %p itself depends on the platform you're working on. You could of course just cast the pointer to an int and display it in hex:
printf("0x%016lx", (unsigned long)ptr);