> > "Alan Ellis" <alan@xxxxxxxxxxxxxx> wrote:
> > [keeping the mangled symbol]
> > > yep.
> > >
> > > you will need to keep the mangled symbol in the lib, but not
> > > export
> > > it
> > > from the header.
> >
> > Why is that=3F Does really anyone refers to that symbol in real
> > life=
> > 3F
>
> I'm wildly speculating, but I could imagine, that a subclass fills in
> the private base class slots of its vtable with pointers to the
> actual
> (private) functions defined in the base class. If that was so, it
> would
> also mean, that a virtual function that was formerly just a reserved
> slot won't work in apps compiled with the old version of the headers.
> Something to be investigated.
It seems that exactly that happens. That means, we need to be extremely
carefully.
CU, Ingo
$ g++ a.cpp -o liba.so -nostart
$ g++ b.cpp -o app -L. -la
$ LIBRARY_PATH=$LIBRARY_PATH:. ./app
A::test()
$ g++ a.cpp -o liba.so -nostart -DUSE_NEW_VERSION
$ LIBRARY_PATH=$LIBRARY_PATH:. ./app
A::test()
A::NastyVirtual() (obsolete)
8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8<
// a.h
class A {
public:
void test();
#ifdef USE_NEW_VERSION
virtual void NewVirtual();
#else
private:
virtual void NastyVirtual();
#endif // USE_NEW_VERSION
};
8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8<
// a.cpp
#include <stdio.h>
//#define USE_NEW_VERSION
#include "a.h"
// test
void
A::test()
{
printf("A::test()\n");
#if USE_NEW_VERSION
NewVirtual();
#endif
}
#if USE_NEW_VERSION
// NewVirtual
void
A::NewVirtual()
{
printf("A::NewVirtual()\n");
}
// NastyVirtual
extern "C"
void
NastyVirtual__1A()
{
printf("A::NastyVirtual() (obsolete)\n");
}
#else
// NastyVirtual
void
A::NastyVirtual()
{
printf("A::NastyVirtual()\n");
}
#endif // USE_NEW_VERSION
8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8<
// b.cpp
#include "a.h"
class B : public A {
};
// main
int
main()
{
B b;
b.test();
return 0;
}