This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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






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