Formatted output of void* ignores uppercase and internal
Martin Sebor
sebor@roguewave.com
Mon Jan 5 17:45:00 GMT 2004
Bradford Castalia wrote:
> When formatting the output of a pointer (void*) the format
> manipulators "uppercase" and "internal" seem to be ignored.
The C++ standard specifies, in 22.2.2.2.2, p12, that pointers are
formatted as if by printf("%p"), which according to 7.19.6.1, p8
of the current C standard produces an implementation-defined
sequence of characters. So the behavior you're seeing is not
incorrect, just unportable (because the values of pointers or
their format are not portable) and perhaps less than useful
(implementations of printf may provide extensions to control
the formatting of pointers that the C++ implementation is not
permitted to take advantage of).
>
> The goal is to produce formatted output of a pointer value
> in hex using uppercase letters, and with all digits of the
> value represented including leading zeros.
If you know the representation of pointers on your architecture
(usually just a plain word), convert the pointer to an integral
type large enough to hold its value and stream that out instead.
Martin
More information about the Gcc-bugs
mailing list