[ale] libg++2.7.1.4 problems.

Joe jknapka at mindspring.com
Tue Apr 30 22:44:42 EDT 1996


Apology in advance - This is probably not the right forum for this
question, but I'm not sure where to direct it, since Mindspring
doesn't carry the comp.os.linux.* groups. (Is there some other news
server I could use that carries those groups?)

It appears that fstreams do not work correctly in libg++2.7.1.4. /
gcc2.7.2 / libc5.3.12. Very simple programs do not work as expected:

/* Run this program with a single argument. It will create a file
   with that name and write some data to it.
   */

#include <iostream.h>
#include <fstream.h>

main(int argc, char* argv[])
{
  char r[128];
  fstream f(argv[1],ios::in|ios::out);
  // Open f for random reading and writing.

  if (f) {
    f << "Hello1." << flush;
    // Write Hello1.

    f.seekg(0,ios::beg);
    // Seek the read pointer to the beginning of the file.

    f >> r;
    // Read the string we just wrote.

    cout << r;
    // Write it to stdout.

    f.seekp(0,ios::end);
    // Seek the write pointer to the end of the file.

    f << "Hello2." << endl;
    // Write Hello2. The file should now contain
    // Hello1.Hello2.

    f.seekg(0,ios::beg);
    // Seek the read pointer back to the beginning.

    f >> r;
    // Read the entire string "Hello1.Hello2.".

    cout << r;
    // Write it to stdout.
  }
}

This code should produce a file containing "Hello1.Hello2.", and write
"Hello1.Hello1.Hello2." to stdout. What it actually does is creates a
file containing "Hello1.", and writes "Hello1." to stdout. It appears
that the seeks do not work at all, and that the second write is
failing in some mysterious way. If I close and reopen the file before
every seek, it works; but I shouldn't have to do that. This issue is
important to me because I am writing code that modifies flat files,
and it must be portable between SunOS/SunC++4.0.1 (where the above code
works as expected) and Linux/gcc2.7.2. (This is the first time I've
found something that works right under SunC++ but not g++; there are
lots of cases where the reverse is true!)

My kernel is 1.2.13 ELF, in case that matters.

If this truly is broken, how can I find out whether it is a known
problem, and whether a fix is imminent? Has anyone else seen this
problem?

Thanks,

-- Joe






More information about the Ale mailing list