1

This is a syntax question. I came across the line:

void (*old_sigint_handler)(int);

And I have no idea what it is doing. It seems like the concatenation of three types with no variable name. I would appreciate clarification!

user2316667
  • 5,444
  • 13
  • 49
  • 71

6 Answers6

3

Make use of cdecl to know what declaration it is exactly. It is C -> English

declare old_sigint_handler as pointer to function (int) returning void

Sunil Bojanapally
  • 12,528
  • 4
  • 33
  • 46
3
void (*old_sigint_handler)(int);

This defines old_sigint_handler to be a pointer to a function which takes an int and returns void, i.e, no value. The parentheses around old_sigint_handler are necessary here else the following:

void *old_sigint_handler(int);

declares a function old_sigint_handler which takes an int and returns a pointer to void type. This is because of the precedence rules in C. Parentheses bind tightly to the indentifier old_sigint_handler than the * making it a function rather than a pointer to a function. Read this to mentally parse complex C declaration - Clockwise/Spiral Rule.

ajay
  • 9,402
  • 8
  • 44
  • 71
  • Thou downvoter, I expect you to teach me what I did wrong, not just downvote. There's no point to it. – ajay Feb 23 '14 at 15:07
1

Is a function pointer, to a function with signature void (int)

miguelao
  • 772
  • 5
  • 12
1

Thats a variable declaration for the variable named old_sigint_handler, that can hold a function pointer to a function that takes an int and returns nothing (void).

nvoigt
  • 75,013
  • 26
  • 93
  • 142
1

It's a declaration of a function pointer named old_sigint_handler that takes a single int and returns nothing.

Lie Ryan
  • 62,238
  • 13
  • 100
  • 144
1

It's a declaration for a function pointer named old_sigint_handler to a function that takes an int and returns void.

user2485710
  • 9,451
  • 13
  • 58
  • 102