This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/1039: cout does not give correct output with pointer ++
- To: gcc-bugs at gcc dot gnu dot org, lid at ecn dot purdue dot edu
- Subject: Re: c++/1039: cout does not give correct output with pointer ++
- From: Benjamin Kosnik <bkoz at redhat dot com>
- Date: Mon, 11 Dec 2000 12:08:09 -0800
for the following:
#include <iostream>
int main()
{
using namespace std;
int i = 5;
int* p = &i;
int i2 = 5;
int* p2 = &i;
// 1
cout << "combined ";
cout << p << ":" << *p << ":" << p++ << ":" << *p++ << endl;
// 2
cout << "separate ";
cout << p2 << ":" << *p2 << ":";
cout << p2++ << ":" << *p2++ << endl;
return 0;
}
I get, with current CVS on x86/linux:
%a.out
combined 0xbffffacc:134523401:0xbffffac8:5
separate 0xbffffac4:5:0xbffffac8:5
This is actually correct: look at precedence rules for operators, and
the way iostream operators are constructed.
ie,
cout << p2 << ":" is equivalent to
(cout.operator<<p2)).operator<<(":")
-benjamin