C Callbacks

N

Noah Roberts

The functions I am using are not standard, but this is a standard question.

I was under the understanding that you could create a Functor and use it
in place of the function pointer argument to C functions. I haven't
been able to so either I am doing it wrong or I misunderstood.

I am trying to override my signal handler for the SIGCHLD unix signal:

Engine::SIGHandler Engine::sigchld_handler;

Engine::SIGHandler::SIGHandler()
{
signal(SIGCHLD, (void (*)(int))*this);
/*
The above was also tried with (void (*)(int))this which compiles but
blows up with SIGSEGV "in Engine::sigchld_handler ()".
*/
}


void Engine::SIGHandler::eek:perator()(int sig)
{
int status, exit_val;
pid_t pid;

if ((pid = waitpid(-1, &status, WNOHANG)) < 0)
return;

map<pid_t, Engine*>::iterator f = engine_processes.find(pid);
if (f != engine_processes.end())
f->second->handleSigChld(status);
}

So then, the question...

Is what I am attempting possible? How is it done if so?

thanks,
NR
 
N

Noah Roberts

John said:
Sorry but you misunderstood. C functions can only accept function pointers.
I think you are confusing the situation with template classes and template
functions which can accept funciton pointers or functors.
DOH!

thanks.


john
 
J

John Harrison

Noah Roberts said:
The functions I am using are not standard, but this is a standard question.

I was under the understanding that you could create a Functor and use it
in place of the function pointer argument to C functions. I haven't
been able to so either I am doing it wrong or I misunderstood.

Sorry but you misunderstood. C functions can only accept function pointers.
I think you are confusing the situation with template classes and template
functions which can accept funciton pointers or functors.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top