[gnu.g++.bug] stream output on Sun 4

tbaker@CSE.OGC.EDU (Thomas Baker) (03/16/89)

 
I would be surprised if you haven't seen this one before.  The stream
output for g++ on the Sun 4/260 is unpredictable.  The following
program works correctly using g++ on Sun 3's and with ATT C++ on the
Sun 4, Sun 3, and Sequent Symmetry.  I don't have access to a g++
version on the Symmetry so I don't know what the results would be.
I am using g++ version 1.32.0, and Sun OS version 4.0.
 
Here is the program, the compile command that I used is listed at the
beginning of the source.  The source is t.c, and the executable is tt,
a second executable (t2) was made when the output statement that is in
main() was commented out.
 
--------------------------> Source <---------------------------------
// -*- Mode: c++ -*-
//
// Buggy program by Tom Baker
// compile: g++ -g -o tt t.c
 
#include <stream.h>
 
 
class base
{
 public:
  int value;
  base(int);
  int f();
};
 
base::base(int v) 
{
value = v;
cout << "base::base, v = " << v << ", value = " << value << "\n";
};
 
int base::f() 
{
  cout << "f called, value = " << value << "\n";
  return(0);
}
 
main()
{
  int x = 7;
  base c(x);
  cout << "The value of x is " << x << "\n"; // this line changes the output
  c.f();
}
------------------------> End of Source <--------------------------------
 
All of the output statements should print out the value of the integer
that is assigned in the first line of main() (7 in this case).  The
actual value output is unpredictable.  I was amazed to find out that
the output changes when you redirect the output to a file!  I will not
even guess how this happens.  Here is a script of the output.
 
--------------------------> Script <-------------------------------------
Script started on Wed Mar 15 08:47:43 1989
thor[1] tt
base::base, v = 0, value = 0
The value of x is 0
f called, value = 7
thor[2] tt >ttout
thor[3] more ttout
base::base, v = 0, value = 0
The value of x is 0
f called, value = -133608280
thor[4] t2
base::base, v = 16, value = 16
f called, value = 0
thor[5] t2 >t2out
thor[6] more t2out
base::base, v = 16, value = 16
f called, value = 0
thor[7] exit
thor[8] 
script done on Wed Mar 15 08:49:01 1989
---------------------> End of Script <--------------------------------
 
I have on occasion had problems where the streams output eats parts of
string constants that are output, but the program is too big to send
to you.  I have traced the above program with gdb+ and all the values
are assigned correctly.  Has this bug been fixed in later versions?
 
I hope this gives you enough to work with.
 
Thomas Baker                    UUCP:  ..ucbvax!tektronix!ogccse!tbaker
Oregon Graduate Center          CSNET: tbaker@cse.ogc.edu
Beaverton, Oregon 97005