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,116
  • 11
  • 45
  • 68

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
  • 11,964
  • 4
  • 34
  • 43
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,041
  • 7
  • 37
  • 68
  • 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
  • 742
  • 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
  • 68,786
  • 25
  • 88
  • 134
1

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

Lie Ryan
  • 58,581
  • 13
  • 95
  • 141
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,077
  • 10
  • 55
  • 95