home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16607 < prev    next >
Encoding:
Text File  |  1992-11-19  |  2.1 KB  |  61 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: ostream or ostream_withassign
  5. Message-ID: <1992Nov20.002722.24762@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1992Nov19.043332.931@bellahs.com>
  8. Date: Fri, 20 Nov 1992 00:27:22 GMT
  9. Lines: 50
  10.  
  11. jjamison@bellahs.com (John Jamison RD AC) writes:
  12.  
  13. >I'm getting an "Illegal Instruction" crash in a program. The situation
  14. >is a function, void foo_print(ostream& o). The caller is calling
  15. >foo_print(cerr).  In foo_print, the illegal instruction occurs during
  16. >a statement like o << "Some message text\n";  
  17.  
  18. >With a symbolic debugger (pdb) I look at cerr and o. In the caller,
  19. >the debugger tells me that cerr is an instance of ostream_withassign.
  20. >In foo_print() it tells me that o is of type ostream. They resolve to
  21. >different addresses.
  22.  
  23. >Has anyone else had similar problems (Sun-SPARC, with CenterLine c++)?
  24. >Just what is the difference between an ostream_withassign and an ostream?
  25.  
  26. An ostream_withassign is just an ostream.  It is a hack to allow the
  27. initial creation of the standard streams (cin, cout, cerr, clog)
  28. which are just "withassign" version of istream and ostream.  The
  29. "withassign" versions contain no extra data and are derived directly
  30. from the normal stream class, and so should not change address when
  31. pointers are cast to the normal stream base class.  (See <iostream.h>
  32. for the declarations of these classes.)
  33.  
  34. With the following program:
  35.  
  36.     #include <iostream.h>
  37.  
  38.     void foo(ostream &o)
  39.     {
  40.         cout << "o   :" << &o << endl;
  41.     }
  42.  
  43.     main()
  44.     {
  45.         cout << "cerr:" << &cerr << endl;
  46.         foo(cerr);
  47.         return 0;
  48.     }
  49.  
  50. You should find the same address printed twice.  It may be that the
  51. debugger was giving you the address of the formal parameter ("o" in
  52. my example) rather than the address of the object referred to ("cerr").
  53.  
  54. I suspect that either you are not properly including the iostream
  55. header files where required, or that you have some other programming
  56. error which results in the crash.
  57. -- 
  58.  
  59. Steve Clamage, TauMetric Corp, steve@taumet.com
  60. Vice Chair, ANSI C++ Committee, X3J16
  61.