I am reading "The Linux Programming Interface", where I find signal system call prototype as stated:

#include <signal.h>
void ( *signal(int sig, void (*handler)(int)) ) (int);

What is signal here is it function-pointer or simple function?

I want to understand the reason behind putting last (int).

How come signal() is returning last desposition of SIGXXXX despite having void return type?


The way to read

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

is that it declares a function, signal, which takes as arguments

  • an int
  • and a pointer to a function which itself takes an int and doesn’t return anything

and returns a pointer to a function which takes an int and doesn’t return anything.

The extra brackets correspond to the returned function pointer.

There’s a detailed explanation on Stack Overflow. Unfortunately cdecl.org doesn’t work on this declaration (because cdecl doesn’t either).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.