Re: Signal Handling in C++



"san" <sandeep.gond@xxxxxxxxx> writes:

I have a C++ problem. I am implementing a signal handler inside a class
SignalClass.

You are unlikely to produce anything that will work :(

void SignalClass::handler (int sig) {
cout << sig << endl;

Using functions that are not async-signal safe :(
You'll have mystery crashes for as long as this code shall remain.

int SignalClass::assign(int sig)
{
sigaction sa;
sa.sa_handler = handler; // ERROR at this line

Naturally.

I am getting the compiler error as "Cannot assign
void(SignalClass::*)(int) to extern "C" void(*)(int)"

Did you not understand what the compiler is telling you?

You are trying to establish a non-static member function as a
signal handler. Non-static member functions receive "this" as the
first (hidden) parameter. Since the kernel is not going to supply
any hidden parameters, and since signal handlers are invoked (more
or less) directly by the kernel, the compiler is telling you that
you can't do that. You can only have static member function (or a
non-member function) as a signal handler.

You may also wish to read this thread:
http://groups.google.com/group/comp.unix.programmer/browse_frm/thread/a76c5d449cb4a48f

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
.