This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: libstdc++/17: cout is not a real ostream; dynamic_cast SEGV'sas a result (fwd)




On 4 Dec 1999, Paul Barton-Davis wrote:

> The following reply was made to PR libstdc++/17; it has been noted by GNATS.
> 
> From: Paul Barton-Davis <pbd@Op.Net>
> To: Benjamin Kosnik <bkoz@cygnus.com>
> Cc: libstdc++-gnats@sourceware.cygnus.com
> Subject: Re: libstdc++/17: cout is not a real ostream; dynamic_cast SEGV's as a result 
> Date: Sat, 04 Dec 1999 00:28:46 -0500
> 
>  >> because cout is not a real ostream, but a _fake_ostream,
>  >> dynamic_cast<ClassDerivedFromOstream *> will fail
>  >> when applied to a pointer or reference to cout.
>  >
>  >see http://sourceware.cygnus.com/libstdc++
>  >
>  >that's what this database is for. . . . if you checkout the CVS sources, 
>  >you'll see that cout is indeed a "real" ostream
>  
>  then why does a dynamic_cast<ClassDerivedFromOstream *> segfault when
>  passed a pointer to cout, but not to any other ostream ?
>  
>  perhaps i am getting my streams implementation from some other library
>  like libg++ ?
>  
>  --p
> 

I suspect you are including the headers from the default gcc install and
  linking against the library from libstdc++.

This is an easy mistake to make, because gcc 2.95.x puts its headers in
  {prefix}/include/g++-3, and libstdc++ puts its headers in
  {prefix}/include/g++-v3 . **NOTE THE 'v'** .

So if you installed both gcc and libstdc++ into /usr/local/ (the default
  in both cases) and compiled with

g++ -I/usr/local/include/g++-3 -L/usr/local/lib

(Note the missing 'v')

you would (I think) get a binary that would segfault when a
  dynamic_cast<ostream*> (&cout) was attempted, as the ostream class
  declared in the defalut gcc 2.95.x headers is very different from that
  used in libstdc++.

So use -I{prefix}/include/g++-v3 , and your program should work.
                              ^




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]