Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > signal handling

Reply
Thread Tools

signal handling

 
 
Lionel van den Berg
Guest
Posts: n/a
 
      03-22-2005
Hi all,

I'm trying to do some signal handling using the csignal library but I
can't find and specific examples for C++.

The signal function as defined in C takes a parameter that is the signal
we are registering for, and a second parameter that is the function to call.

What I want to do is specify the function to call as a function of an
instance of "this" class e.g.

void Class::signalHandler( int signal ){}

void Class::someFunction( ) {
signal( SIGINT, this.signalHandler );
}


Obviously this is wrong because it complains about signalHandler not
being a type.

How do I achieve this in C++? Can I achieve this in C++?

Thanks,

Lionel.
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      03-22-2005
* Lionel van den Berg:
>
> I'm trying to do some signal handling using the csignal library but I
> can't find and specific examples for C++.
>
> The signal function as defined in C takes a parameter that is the signal
> we are registering for, and a second parameter that is the function to call.
>
> What I want to do is specify the function to call as a function of an
> instance of "this" class e.g.
>
> void Class::signalHandler( int signal ){}
>
> void Class::someFunction( ) {
> signal( SIGINT, this.signalHandler );
> }
>
>
> Obviously this is wrong because it complains about signalHandler not
> being a type.
>
> How do I achieve this in C++? Can I achieve this in C++?


You don't. 'signal' is generally incompatible with C++. AFAIK the only
things you can reliably do in a handler are (1) to terminate, (2) to do
nothing, or (3) set a global flag of type 'volatile sig_atomic_t', and the
standard notes in particular that a signal handler using exception handling
is likely to have problems.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
 
 
 
Stephen Howe
Guest
Posts: n/a
 
      03-23-2005
> Obviously this is wrong because it complains about signalHandler not being
> a type.
>
> How do I achieve this in C++?


You can't register member functions as a signal handler. Obviously so,
because "this" points to a specific instance of your class with its
associated class data. When your signal is raised, how does it know what
"this" to supply?

class member functions and function pointers are incompatibile.

What you can register is a static class function, because a static class
function is not tied to any specific instance of a class.
static class functions and function pointers can be compatible.

Stephen Howe


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
signal handling and (structured) exception handling Peter C++ 34 10-17-2009 10:03 AM
Re: How to make an internal signal embedded deep in hierarchy to a gloal output signal Weng Tianxiang VHDL 2 01-30-2007 12:58 PM
Aside from delta cycles and/or resolution functions, how can the effective value of a signal differ from a driving signal of its? Colin Paul Gloster VHDL 0 01-11-2007 01:31 PM
threading.Thread vs. signal.signal Jack Orenstein Python 0 09-17-2005 11:24 PM
Async-signal safe functions in signal handlers (unix) Michael Pronath Python 1 01-03-2005 01:10 PM



Advertisments