Xref: utzoo comp.lang.c:23689 comp.unix.wizards:19285 Path: utzoo!censor!geac!jtsv16!uunet!wuarchive!udel!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: (* func)(fred, bert) Message-ID: <20668@mimsy.umd.edu> Date: 10 Nov 89 03:24:51 GMT References: <2387@stl.stc.co.uk> Followup-To: comp.lang.c Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 58 In article <2387@stl.stc.co.uk> dsr@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@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@cs.umd.edu Path: uunet!mimsy!chris