C declaration from standard signal Library

前端 未结 4 1362
终归单人心
终归单人心 2020-12-30 12:15

So can someone explain what this is supposed to do:

void (*signal(int sig, void (*func)(int)) ) (int);

It is a definition taken from the st

4条回答
  •  一生所求
    2020-12-30 12:57

    Basically it allows to decide how to handle a specific signal (identified by argument int sig) sent to your program.

    The void (*func)(int) is a pointer to the function that will handle the signal (you can provide a custom one or use SIG_DFL SIG_IGN which are default actions to manage it normally or ignore it).

    The function signal then returns the pointer to the handler present BEFORE the call of this function or SIG_ERR is an error occurred. This can be used to restore the default handler lately when you've done with custom behaviour.

提交回复
热议问题