wagner@smith.cs.unc.edu (Michael Wagner) (03/23/91)
A week or so ago, I posted news asking about
UNIX signals in C++. As many of you may
recall, the basic problem is that the signal()
call expects a pointer to a function as its
second parameter.
Here's the solution that worked (note that
the SIG_PF worked with Interviews' <signal.h>
file, though SIG_PFV worked with Sun's AT&T
<signal.h>):
/******************************/
// an ugly but invaluable kludge from Jon Leech
/* A *global* pointer to the object whose
method is to be invoked upon receiving SIGINT.
The handler has no way of getting at local variables.
*/
Texted *t;
/* This declares a signal handler. */
SIG_PF sighook(int, SIG_PF) {
// Invoke the method
t->Update();
}
/********************************/
void Texted::Update() {
signal(SIGUSR1, (SIG_PF)sighook);
printf("Update invoked!\n");
.
.
.
}
.
.
.
Texted::Texted () {
signal(SIGUSR1, (SIG_PF)sighook);
.
.
.
}
.
.
.
The "Jon Leech" mentioned is leech@cs.unc.edu.
I hope this save's someone some time and
agony.