This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Formatted output of void* ignores uppercase and internal


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]