Re: Signal Handling in C++
- From: Paul Pluzhnikov <ppluzhnikov-nsp@xxxxxxxxxxx>
- Date: Mon, 13 Feb 2006 22:29:26 -0800
"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.
.
- References:
- Signal Handling in C++
- From: san
- Signal Handling in C++
- Prev by Date: How to link NEWT library in graphics program
- Next by Date: Re: Cross compiling from solaris x86 to sparc?
- Previous by thread: Signal Handling in C++
- Next by thread: Re: Signal Handling in C++
- Index(es):