This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: When C++ obeject is passed to C function
- From: "VallabhaN" <VallabhaN at bristol dot com>
- To: Eljay Love-Jensen <eljay at adobe dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 6 Aug 2002 22:01:29 +0530
- Subject: Re: When C++ obeject is passed to C function
Hi Eljay,
Thanks for your reply. I have the same sample working fine on 32 bit m/c
with gcc 2.96. Is this the problem specific to 64 bit gcc 3.1 ??
Thanks again
-Vallabha
To: VallabhaN/Bristol Technology@Bristol Technology, gcc-help@gcc.gnu.org
cc:
Subject: Re: When C++ obeject is passed to C function
Hi Vallabha,
Don't try to put instance method virtual function pointers into a C
structure of function pointers. An instance method virtual function
pointer is a different animal.
You should use glue/stub routines.
class Base {
public:
// Option #1 entry stub...
static void KickEntry(void* self) {
Base* base = static_cast<Base*>(self);
base->KickSelf();
}
// ...end-of-#1.
// Option #2 entry stub...
/*final*/ void Kick() { KickSelf(); }
// ... end-of-#2.
virtual void KickSelf() = 0;
};
Put KickEntry() or Kick() into your C structure of function
pointers. KickSelf() won't work.
My preference is KickEntry(), but if you are careful Kick() will work too.
Also, strongly consider making KickSelf() private. Or at least, protected.
--Eljay