Can someone explain to me how 'sigaction' works?
I'm having difficulties understanding the way sigaction()
works.
In <signal.h>
, sigaction is defined as
int sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
But sigaction
is also defined in bits/si开发者_Python百科gaction.h
as a structure. I'm confused here, can a struct in C be made callable?
Can someone please give me a brief explanation on this?
The function is called sigaction
, the structure is called struct sigaction
. Functions and structures exist in different namespaces in C. It is similar to the way you can do this:
#include <stdio.h>
struct x {
int x;
};
static int
x(struct x *x) {
return x->x;
}
int
main(void) {
struct x y;
/* But not "struct x x" as we want to call the "x" function below. */
y.x = 1;
printf("%d\n", x(&y));
return 0;
}
And the compiler can sort out which x
is which by the various namespaces. But this example is rather excessive and would get you some dirty looks if you did something like this in real life.
精彩评论