In CPython, 0x%p style is preferred for address, I think we should use it instead of %p for consistency.
They also have a check to ensure presence of leading 0x:
case 'p':
sprintf(buffer, "%p", va_arg(vargs, void*));
assert(strlen(buffer) < sizeof(buffer));
/* %p is ill-defined: ensure leading 0x. */
if (buffer[1] == 'X')
buffer[1] = 'x';
else if (buffer[1] != 'x') {
memmove(buffer+2, buffer, strlen(buffer)+1);
buffer[0] = '0';
buffer[1] = 'x';
}
WRITE_BYTES(buffer);
break;
Above code-snippet is from bytesobject.c, a similar implementation can also be found in unicodeobject.c
In CPython,
0x%pstyle is preferred for address, I think we should use it instead of%pfor consistency.They also have a check to ensure presence of leading
0x:Above code-snippet is from
bytesobject.c, a similar implementation can also be found inunicodeobject.c