Search the web
Sign In
New User? Sign Up
cheapthreads · cheap_threads
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
C++ class method to be called by scheduler   Message List  
Reply | Forward Message #26 of 89 |
Re: [cheapthreads] C++ class method to be called by scheduler

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



Thu Nov 27, 2003 3:49 pm

jm407a
Offline Offline
Send Email Send Email

Forward
Message #26 of 89 |
Expand Messages Author Sort by Date

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...
Antz
antz_ii
Offline Send Email
Nov 27, 2003
2:34 pm

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...
Scott McKellar
jm407a
Offline Send Email
Nov 27, 2003
3:52 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help