Reputation: 5634
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!
Upvotes: 1
Views: 182
Reputation: 9680
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.
Upvotes: 3
Reputation: 12658
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
Upvotes: 3
Reputation: 9801
It's a declaration for a function pointer named old_sigint_handler
to a function that takes an int
and returns void
.
Upvotes: 1
Reputation: 64915
It's a declaration of a function pointer named old_sigint_handler that takes a single int and returns nothing.
Upvotes: 1
Reputation: 77324
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).
Upvotes: 1