[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#319744: g++-4.0: cout << &charvar is scrambled



Package: g++-4.0
Version: 4.0.1-2
Severity: normal

If one tries to output an address of a character variable or a pointer
to a character variable, the output is scrambled.

Consider the following test program:

#include <iostream>
#include <stdio.h>

main () {

char a = 'a';
bool b = 0;
short s = 0;
int i = 4711;
char *pa = &a;
int *pi = &i;
void *vpa = &a;

printf("printf Output of address of i is %lx\n", &i);
printf("printf Output of pointer to i is %lx\n", pi);
std::cout << "cout Output of pointer to i is " << pi << '\n';
std::cout << "cout Output of address of i is " << &i << '\n';
std::cout << "cout Output of pointer to  a is " << pa << '\n';
std::cout << "cout Output of void pointer to  a is " << vpa << '\n';
std::cout << "cout Output of address of a is " << &a << '\n';
std::cout << "cout Output of address of a is ";
std::cout << &a;
std::cout << '\n';
std::cout << "cout Output of address of b is " << &b << '\n';
std::cout << "cout Output of address of s is " << &s << '\n';

printf("printf Output of address of a is %lx\n", &a);

}

It has the following output:

printf Output of address of i is bffff874
printf Output of pointer to i is bffff874
cout Output of pointer to i is 0xbffff874
cout Output of address of i is 0xbffff874
cout Output of pointer to  a is a{øÿ¿tøÿ¿{øÿ¿èøÿ¿téÙ·
cout Output of void pointer to  a is 0xbffff87b
cout Output of address of a is a{øÿ¿tøÿ¿{øÿ¿èøÿ¿téÙ·
cout Output of address of a is a{øÿ¿tøÿ¿{øÿ¿èøÿ¿téÙ·
cout Output of address of b is 0xbffff87a
cout Output of address of s is 0xbffff878
printf Output of address of a is bffff87b


As one can see with od -c, there are some unprintable characters:

0000000   p   r   i   n   t   f       O   u   t   p   u   t       o   f
0000020       a   d   d   r   e   s   s       o   f       i       i   s
0000040       b   f   f   f   f   8   7   4  \n   p   r   i   n   t   f
0000060       O   u   t   p   u   t       o   f       p   o   i   n   t
0000100   e   r       t   o       i       i   s       b   f   f   f   f
0000120   8   7   4  \n   c   o   u   t       O   u   t   p   u   t    
0000140   o   f       p   o   i   n   t   e   r       t   o       i    
0000160   i   s       0   x   b   f   f   f   f   8   7   4  \n   c   o
0000200   u   t       O   u   t   p   u   t       o   f       a   d   d
0000220   r   e   s   s       o   f       i       i   s       0   x   b
0000240   f   f   f   f   8   7   4  \n   c   o   u   t       O   u   t
0000260   p   u   t       o   f       p   o   i   n   t   e   r       t
0000300   o           a       i   s       a   { 370 377 277   t 370 377
0000320 277   { 370 377 277 350 370 377 277   t 351 331 267 001  \n   c
0000340   o   u   t       O   u   t   p   u   t       o   f       v   o
0000360   i   d       p   o   i   n   t   e   r       t   o           a
0000400       i   s       0   x   b   f   f   f   f   8   7   b  \n   c
0000420   o   u   t       O   u   t   p   u   t       o   f       a   d
0000440   d   r   e   s   s       o   f       a       i   s       a   {
0000460 370 377 277   t 370 377 277   { 370 377 277 350 370 377 277   t
0000500 351 331 267 001  \n   c   o   u   t       O   u   t   p   u   t
0000520       o   f       a   d   d   r   e   s   s       o   f       a
0000540       i   s       a   { 370 377 277   t 370 377 277   { 370 377
0000560 277 350 370 377 277   t 351 331 267 001  \n   c   o   u   t    
0000600   O   u   t   p   u   t       o   f       a   d   d   r   e   s
0000620   s       o   f       b       i   s       0   x   b   f   f   f
0000640   f   8   7   a  \n   c   o   u   t       O   u   t   p   u   t
0000660       o   f       a   d   d   r   e   s   s       o   f       s
0000700       i   s       0   x   b   f   f   f   f   8   7   8  \n   p
0000720   r   i   n   t   f       O   u   t   p   u   t       o   f    
0000740   a   d   d   r   e   s   s       o   f       a       i   s    
0000760   b   f   f   f   f   8   7   b  \n
0000771

Initially, I started with stable, i.e. g++-3.3 and g++3.4. Those
versions have the same Problem.  Perhaps it is located in libc6?

-- System Information:
Debian Release: 3.1
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.11-1-686
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)

Versions of packages g++-4.0 depends on:
ii  gcc-4.0                     4.0.1-2      The GNU C compiler
ii  gcc-4.0-base                4.0.1-2      The GNU Compiler Collection (base 
ii  libc6                       2.3.2.ds1-22 GNU C Library: Shared libraries an
ii  libstdc++6-4.0-dev          4.0.1-2      The GNU Standard C++ Library v3 (d

g++-4.0 recommends no packages.

-- no debconf information



Reply to: