(* func)(fred, bert)
Chris Torek
chris at mimsy.umd.edu
Fri Nov 10 14:24:51 AEST 1989
In article <2387 at stl.stc.co.uk> dsr at stl.stc.co.uk (David Riches) writes:
>I want a function with the following interface, that does some actions
>when a signal activates it :-
I had a hard time figuring out what you meant to happen, since your
example is not anything like legal C. (Refer to <2387 at stl.stc.co.uk>
to see the original code.) I think, though, that what you want is
to call a function (`error') on a signal such as SIG_ALRM. This much
you can do directly in (proposed) standard C. However, you want that
function to be passed two arguments that can be specified at the
call to signal(). This you cannot do directly. You will have to
use a global variable (horrors! :-) ).
According to the pANS, a signal function is called with the signal
number, and nothing else. Hence, something like this will be
required.
struct info_needed_during_signal_handler {
void (*fn)(int, int *);
int code;
int *status;
} siginfo;
void signal_catch_function(int sig) {
(void) signal(SIG_ALRM, signal_catch_function);
(*siginfo.fn)(siginfo.code, siginfo.status);
}
void set_catch(void (*fn)(int, int *), int code, int *status) {
siginfo.code = code;
siginfo.status = status;
siginfo.fn = fn;
(void) signal(SIG_ALRM, signal_catch_function);
}
Then, instead of:
>[mysterious version of error() deleted]
>
>VOID main()
> {
> signal(SIG_ALARM, error(101, &stat); <----------------- (B)
...
you would write
void error(int code, int *status) {
*status = Fn(code);
}
int main() { /* main returns an int, if it returns! */
set_catch(error, 101, &stat);
...
}
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at cs.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list