[Bug c++/14417] New: output streams and post-increment operator have incorrect output.
mcvick_e at iname dot com
gcc-bugzilla@gcc.gnu.org
Wed Mar 3 20:59:00 GMT 2004
Utilizing the post increment operator within a stream operation does not result
in the expected output. Output is reversed. Based on the grammer of the
language, this should work as expected and not as currently implemented.
THe following program will replicate the problem:
#include <iostream>
#include <fstream>
using namespace std;
char *str = "0123456789ABCDEF";
int main(int argc, char **argv)
{
char *ptr;
#if defined(COUT_TOO)
ptr = str;
cout << *ptr++ << *ptr++ << ' ';
cout << *ptr++ << *ptr++ << ' ';
cout << *ptr++ << *ptr++ << ' ';
cout << *ptr++ << *ptr++ << ' ';
cout << *ptr++ << *ptr++ << ' ';
cout << *ptr++ << *ptr++ << ' ';
cout << *ptr++ << *ptr++ << ' ';
cout << *ptr++ << *ptr++ << ' ';
cout << endl;
#endif
ostream *outStream;
outStream = new ofstream("foo.txt");
ptr = str;
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << *ptr++ << *ptr++ << ' ';
*outStream << endl;
delete outStream;
// Same concept, different syntax works.
#if defined(COUT_TOO)
ptr = str;
cout << *ptr++;
cout << *ptr++ << ' ';
cout << *ptr++;
cout << *ptr++ << ' ';
cout << *ptr++;
cout << *ptr++ << ' ';
cout << *ptr++;
cout << *ptr++ << ' ';
cout << *ptr++;
cout << *ptr++ << ' ';
cout << *ptr++;
cout << *ptr++ << ' ';
cout << *ptr++;
cout << *ptr++ << ' ';
cout << *ptr++;
cout << *ptr++ << ' ';
cout << endl;
#endif
outStream = new ofstream("bar.txt");
ptr = str;
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << *ptr++;
*outStream << *ptr++ << ' ';
*outStream << endl;
}
The above program was compiled with the following command:
g++ -O0 -o foobar test.cxx -DCOUT_TOO
The output on the screen and found in the files is thus:
10 32 54 76 98 BA DC FE
01 23 45 67 89 AB CD EF
The specs of the compiler obtained with g++ -v is:
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --disable-libunwind-exceptions --with-system-zlib
--enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.3.3 20040216 (Red Hat Linux 3.3.3-2)
I have even tried the latest snapshot of GCC 3.3.3 and it fails as well. I also
compiled 3.3.1 and used it with the same results.
--
Summary: output streams and post-increment operator have
incorrect output.
Product: gcc
Version: 3.3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mcvick_e at iname dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i386-redhat-linux
GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14417
More information about the Gcc-bugs
mailing list