You can't call a C++ member function directly from C.
In the case of a non-static member function, the compiler arranges to
pass an additional parameter -- a pointer to the object instance --
that does not appear in the source code. So your int run(void * pData)
is really int run(PortChecker * pPC, void * pData).
On many systems the scheduler could probably invoke a static member
function, which does not receive such an additional parameter.
However the Standard does not guarantee that this approach will work.
The portable approach is to write a thin wrapper, which will probably
be some variant of the following:
extern "C" int run_PortChecker( void * pData )
{
PortChecker * pPC = static_cast< PortChecker * >( pData );
return pPC->run();
}
The above is uncompiled, untested, and probably garbled somewhere. but
it should point you in the right direction.
Scott McKellar mck9@...
http://home.swbell.net/mck9/ct/
Antz wrote:
>
> Greetingz all.
>
> Once again I have stumbled across a problem using the Cheap_Threads C-code
> in conjunction with my own C++ code. The story goes a bit like this...
>
> I have a class called PortChecker (for example), this class contains a
> member function called with the prototype: int run(void * pData)
>
> Now this run method is what I want the Cheap_Threads scheduler to call.
> I've tried a number of things including returning function pointers (with
> no success).
>
> Anyone have any useful ideas?
>
> Thnx.
>
> -Antz