0

I am novice in C. Can you tell me what does it mean?

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

I ask about syntax, not about error handling. I understand all completely except last bracket (int).

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

This is the level on which I understand. We make prototype for function which has two parameters(integer number, pointer to function with integer parameter and nothing return) and example return void.

Thank you.

RobJob
  • 15
  • 4
  • Re "*This is the level on which I understand.*", Not quote. `void (*...)` doesn't mean "returns void". In fact, `void (*...)` makes no sense at all. It's half of the return type. – ikegami Nov 12 '21 at 02:04

2 Answers2

0

It declares a function called signal.

  • Its first argument (sig) is of type int.
  • Its second argument (func) is of type void (*)(int).
  • Its return type is void (*)(int).

void(*)(int) indicates a function pointer.

  • The function's only argument is of type int.
  • The function's return type is void.

The following is equivalent:

typedef void (*SignalHandler)(int);

SignalHandler signal(int sig, SignalHandler func);
ikegami
  • 367,544
  • 15
  • 269
  • 518
0

That is to say, signal is a function that returns a pointer to another function. This second function takes a single int argument and returns void. The second argument to signal is similarly a pointer to a function returning void which takes an int argument.

vegan_meat
  • 878
  • 4
  • 10