You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by San Lin <Sa...@galegroup.com> on 2001/09/28 18:24:31 UTC

xerces-c and dynamic_cast

We are experiencing a problem when using xerces and dynamic_cast.

The problem happens on a RedHat (7.1) Linux kernal 2.4 that has a gnu gcc
with the library 
libstdc++-3-libc6.2-2-2.10.0.a libstdc++-3-libc6.2-2-2.10.0.so

An help is appreciated.

san


P.S.

Bellow is a simple test code, cast.cpp

Compile and test it with these steps:

1. compile
g++ -Wall -g -I. -I/usr/local/xerces-c1_5_1-linux/include  -I/opt/mqm/inc -c
-o cast.o cast.cpp

2. load to create qt
g++ -o qt query.o cast.o 

3. load to create qf, with the lib xerces
g++ -o qf query.o cast.o  -lxerces-c1_5_1
-L/usr/local/xerces-c1_5_1-linux/lib

qt works:
[slin@ltang2 ~/csi]$ ./qt
b is indeed a B

while qf crashes:
[slin@ltang2 ~/csi]$ ./qf
Segmentation fault (core dumped)


------cast.cpp---

#include <iostream>
#include <string>

class A 
{
  char* name;
public:
  A()
  {
    name = "A";
  }
  virtual string GetName () = 0;
};

class B : public A
{
  char* name;
public:
  B()
  {
    name = "B";
  }
  virtual string GetName()
  {
    return name;
  }
};
  
int main(int argc, char* argv[]) 
{
    A* b = new B;

    if (dynamic_cast<B*>(b)) {
	cout << "b is indeed a B" << endl;
    }
    else {
	cout << "b is not a B" << endl;
    }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: xerces-c and dynamic_cast

Posted by "Scott A. Herod" <he...@interact-tv.com>.
Hi,

I've also had problems using dynamic casts with Xerces linked code.
I still think that it is because my version of Xerces was compiled
with gcc 2.95.2 while I compile locally with 2.96.  Your example 
still works if I compile it with 2.95.2 but fails just as you
mention when I compile the test with 2.96.  To really test, I'll
need to compile xerces with 2.96.

Since vtable layouts change between gcc versions, I can understand
the casting problems.  ( Don't start me on the evils of COM. )

Check your version of libxerces-c* to see which gcc was used to build
it.  ( Is there a better way than opening it with xemacs and searching
for the string "libstdc"? )

Scott

San Lin wrote:
> 
> We are experiencing a problem when using xerces and dynamic_cast.
> 
> The problem happens on a RedHat (7.1) Linux kernal 2.4 that has a gnu gcc
> with the library
> libstdc++-3-libc6.2-2-2.10.0.a libstdc++-3-libc6.2-2-2.10.0.so
> 
> An help is appreciated.
> 
> san
> 

<snip code>

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org