Formatted output of void* ignores uppercase and internal

Bradford Castalia Castalia@idaeim.com
Sun Jan 4 02:50:00 GMT 2004


When formatting the output of a pointer (void*) the format manipulators
"uppercase" and "internal" seem to be ignored.

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. However, the uppercase and internal format manipulators
are ignored when the output value is a void* type (as one would expect to
cast any formatted output of a pointer). When the pointer is forcibly
cast as a unsigned int, the format manipulators have the expected result.

The following example program demonstrates the effect:

#include <iostream>
#include <iomanip>
using namespace std;

int
main (int count, char** argument)
{
void* pointer = *argument;
cout << "As void*: "
     << hex << setfill ('0') << showbase << uppercase
     << setw (12) << internal
     << pointer << endl;
cout << "As u_int: "
     << hex << setfill ('0') << showbase << uppercase
     << setw (12) << internal
     << reinterpret_cast<unsigned int>(pointer) << endl;
}

The width was set to 12 to exercise the internal zero padding of the hex
formatting. After compiling (g++ -o try try.cc) the output is:

As void*: 000xbfbfe068
As u_int: 0X00BFBFE068

I have tested this on FreeBSD 4.8-STABLE (x86) with gcc 3.3.1, and Solaris
5.8 (sun4u) with gcc 3.2.2 and get the same results. I am attaching a log
of the -v compiler output and the compressed try.ii -save-temps output from
the FreeBSD system.

-- 

Bradford Castalia

"Build an image in your mind, fit yourself into it."

P.S. I would have submitted through bugzilla, but I saw no way to provide
the compressed *.ii file requested in the reporting instructions.
-------------- next part --------------
Reading specs from /opt/pub/bin/../lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/specs
Configured with: ./..//gcc-3.3-20030804/configure --disable-nls --with-gxx-include-dir=/usr/local/lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/include/c++/ --with-system-zlib --disable-shared --prefix=/usr/local i386-portbld-freebsd4.8
Thread model: posix
gcc version 3.3.1 [FreeBSD]
 /opt/pub/bin/../lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/cc1plus -E -D__GNUG__=3 -quiet -v -iprefix /opt/pub/bin/../lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/ -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=1 try.cc try.ii
ignoring nonexistent directory "/opt/pub/i386-portbld-freebsd4.8/include"
ignoring nonexistent directory "/usr/local/i386-portbld-freebsd4.8/include"
ignoring duplicate directory "/usr/local/lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/include/c++"
ignoring duplicate directory "/usr/local/lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/include/c++/i386-portbld-freebsd4.8"
ignoring duplicate directory "/usr/local/lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/include/c++/backward"
ignoring duplicate directory "/usr/local/lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/pub/lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/include/c++
 /opt/pub/lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/include/c++/i386-portbld-freebsd4.8
 /opt/pub/lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/include/c++/backward
 /opt/pub/lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/include
 /usr/local/include
 /usr/include
End of search list.
 /opt/pub/bin/../lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/cc1plus -fpreprocessed try.ii -quiet -dumpbase try.cc -auxbase try -version -o try.s
GNU C++ version 3.3.1 [FreeBSD] (i386-portbld-freebsd4.8)
	compiled by GNU C version 3.3.1 [FreeBSD].
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32318
 as -o try.o try.s
 /opt/pub/bin/../lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/collect2 -V -dynamic-linker /usr/libexec/ld-elf.so.1 -o try /usr/lib/crt1.o /usr/lib/crti.o /opt/pub/bin/../lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/crtbegin.o -L/opt/pub/bin/../lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1 -L/opt/pub/bin/../lib/gcc-lib -L/usr/local/lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1 -L/opt/pub/bin/../lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/../../.. -L/usr/local/lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/../../.. try.o -lstdc++ -lm -lgcc -lc -lgcc /opt/pub/bin/../lib/gcc-lib/i386-portbld-freebsd4.8/3.3.1/crtend.o /usr/lib/crtn.o
GNU ld version 2.12.1 [FreeBSD] 2002-07-20
  Supported emulations:
   elf_i386
-------------- next part --------------
A non-text attachment was scrubbed...
Name: try.ii.gz
Type: application/x-gzip
Size: 79514 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20040104/a54135fd/attachment.bin>


More information about the Gcc-bugs mailing list