Skip to content

Addresses are not printed with leading 0x  #5262

@microdev1

Description

@microdev1

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions