C declaration from standard signal Library

前端 未结 4 1360
终归单人心
终归单人心 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

    The man page makes this declaration easier to understand by introducing a typedef as:

    typedef void (*sighandler_t)(int);
    
    sighandler_t signal(int signum, sighandler_t handler);
    

    sighandler_t is defined as a pointer to a function that accepts an int and returns void.

    signal is a function that accepts an int (signal number) and a function pointer and returns a function pointer.

提交回复
热议问题