This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Formatted output of void* ignores uppercase and internal
- From: Martin Sebor <sebor at roguewave dot com>
- To: Castalia at idaeim dot com
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 05 Jan 2004 10:43:30 -0700
- Subject: Re: Formatted output of void* ignores uppercase and internal
- References: <3FF77F75.4A32A23F@idaeim.com>
- Reply-to: gcc-bugs at gcc dot gnu dot org
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