Reputation: 323
I'm trying to understand a code which have the following lines:
void terminate_pipe(int);
code code code...
struct sigaction new_Sigiterm;
new_Sigiterm.sa_handler = terminate_pipe;
My question are:
What is the meaning of calling a function like this? Is it going to
just put NULL
as the parameter?
It is void, so new_Sigiterm.sa_handler
will be NULL
no matter what?
thanks.
Upvotes: 0
Views: 109
Reputation: 111
Code like this assignment is setting a handler (sometimes called a function pointer): Basically, the address of the function to run, at a given time.
The syntax for this in C is to name the function, but don't put ()
on the end. That returns the address of the function.
new_Sigiterm.sa_handler = terminate_pipe;
Upvotes: 1
Reputation: 1494
new_Sigiterm.sa_handler
is most likely a pointer that points to a function. By running
new_Sigiterm.sa_handler = terminate_pipe;
It's similar to saying
new_Sigiterm.sa_handler = &terminate_pipe;
(Like in pointers). This is not running the function, it's just making a pointer that points to the function, if you "run" the pointer, the pointed function will run.
This is how to declare function pointer:
void function(int x);
int main()
{
//Pointer to function
void (*foo) (int);
//Point it to our function
foo = function;
//Run our pointed function
foo(5);
}
More info about function pointers
Upvotes: 3
Reputation: 5741
void terminate_pipe(int);
is not calling of function it is Forward declaration of function.new_Sigiterm.sa_handler
sa_handler
is a Function Pointer.Upvotes: 0