In the ANSI standard, the signal () statement is as follows:
Void (* signal (INT Sig, void (* func) (INT)
Signal is a function that returns a function pointer. the function that the latter points to (the return value of signal) accepts an int parameter and returns void. The signal function has two parameters: SIG (INT type) and func (void (*) (INT ).
Void (* func) (INT) is a function pointer. The function to which it points accepts an int parameter, and the return value is void.
The following is simplified using typedef:
Typedef void (* ptr_to_func) (INT );
Ptr_to_func signal (INT, ptr_to_func );
An example on the Internet:
# Include <stdio. h>
Enum{Red, green, blue };
Void outputsignal (intSIG)
{
Printf ("the signal you/'ve input is :");
Switch(SIG)
{
CaseRed:
Puts ("red! ");
Break;
CaseGreen:
Puts ("green! ");
Break;
CaseBlue:
Puts ("blue! ");
Break;
}
}
Void (* signal (INT Sig, void (* func) (INT) (int)
{
Puts ("Hello, world! ");
Func (SIG );
ReturnFunc;
}
Int main (void)
{
(* Signal (Green ,&Outputsignal) (red );
Return 0;
}
Output:
Hello, world!
The signal you 've input is: Green!
The signal you 've input is: red!