home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: ostream or ostream_withassign
- Message-ID: <1992Nov20.002722.24762@taumet.com>
- Organization: TauMetric Corporation
- References: <1992Nov19.043332.931@bellahs.com>
- Date: Fri, 20 Nov 1992 00:27:22 GMT
- Lines: 50
-
- jjamison@bellahs.com (John Jamison RD AC) writes:
-
- >I'm getting an "Illegal Instruction" crash in a program. The situation
- >is a function, void foo_print(ostream& o). The caller is calling
- >foo_print(cerr). In foo_print, the illegal instruction occurs during
- >a statement like o << "Some message text\n";
-
- >With a symbolic debugger (pdb) I look at cerr and o. In the caller,
- >the debugger tells me that cerr is an instance of ostream_withassign.
- >In foo_print() it tells me that o is of type ostream. They resolve to
- >different addresses.
-
- >Has anyone else had similar problems (Sun-SPARC, with CenterLine c++)?
- >Just what is the difference between an ostream_withassign and an ostream?
-
- An ostream_withassign is just an ostream. It is a hack to allow the
- initial creation of the standard streams (cin, cout, cerr, clog)
- which are just "withassign" version of istream and ostream. The
- "withassign" versions contain no extra data and are derived directly
- from the normal stream class, and so should not change address when
- pointers are cast to the normal stream base class. (See <iostream.h>
- for the declarations of these classes.)
-
- With the following program:
-
- #include <iostream.h>
-
- void foo(ostream &o)
- {
- cout << "o :" << &o << endl;
- }
-
- main()
- {
- cout << "cerr:" << &cerr << endl;
- foo(cerr);
- return 0;
- }
-
- You should find the same address printed twice. It may be that the
- debugger was giving you the address of the formal parameter ("o" in
- my example) rather than the address of the object referred to ("cerr").
-
- I suspect that either you are not properly including the iostream
- header files where required, or that you have some other programming
- error which results in the crash.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-