Thread View: gnu.g++.lib.bug
1 messages
1 total messages
Started by Christoph Tietz
Tue, 22 Aug 1989 17:55
Bugfix for Files.cc
Author: Christoph Tietz
Date: Tue, 22 Aug 1989 17:55
Date: Tue, 22 Aug 1989 17:55
67 lines
2608 bytes
2608 bytes
I am working on a SUN3 running SUNOS 4.0 with g++ 1.35.1- and libg++ 1.35.1
Problem:
If you want to do standard I/O during cleanup of static objects around main()
you get in trouble. The problem is, that the destruction of an istream or
ostream for standard I/O calls (over the Filebuf destructor) the close method
of the corresponding file class. This is disastrous for the standard I/O
because it is now no longer closed as the last action of your program. In
fact it is closed at some (early) time during the global cleanup. This
cleanup might try to produce some output afterwards that is never seen.
The destructor for the File class tests on standard I/O and only performs a
flush if stdin, stdout or stderr are found. If you call the File::close
method directly, no test on standard I/O is done.
Fix:
I moved the test on standard I/O from ~File to File::close. The diff for
File.cc follows:
205,206d204
< else if (fp == stdin || fp == stdout || fp == stderr)
< flush();
285c283,286
< close();
---
> if (fp == stdin || fp == stdout || fp == stderr)
> flush();
> else if (fp != 0)
> close();
Now even the following program works as expected:
-----------------------------------------------------------------
#include <stream.h>
ostream sout(1); // standard ostream for init and cleanup
class dummy {
public:
dummy() {sout << "Initialization\n"; sout.flush();}
~dummy() {sout << "Clean Up\n";}
};
dummy A;
main() {
cout << "Hello, world!\n";
}
----------------------------------------------------------------
I hope, I fixed a bug and not a feature...
I am aware of the fact, that the global cleanup cannot be guaranteed to be
done before standard I/O is closed on some machines. The code above will not
work on those machines. So, at best, I have fixed a nonportable feature ;-)
Christoph Tietz
Gesellschaft fuer Mathematik e-mail: tietz@zi.gmd.dbp.de
und Datenverarbeitung tietz@gmdzi.uucp
Schloss Birlinghoven tietz%zi.gmd.dbp.de@relay.cs.net
Postfach 1240 ... !uunet!unido!gmdzi!tietz
D-5205 St. Augustin 1
Federal Republic of Germany
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads