Question

I am fairly new to operating systems and am most comfortable in C++, however I am trying to fill in my knowledge gaps and get used to C syntax.

I keep coming across some syntax which I don't know how to interpret, it is of the following form:

void (*sa_sigaction) (int sig, siginfo_t *si, void *ctx)

There are 3 things that are confusing me:

  1. Is sa_sigaction a pointer? I assume it is the function name. Can it also be a pointer?

  2. Why is sa_sigaction in brackets? Does this have any syntactical relevance?

  3. is 'void ctx' a void pointer? (which is what it looks like to me, but I don't understand why a void pointer would be a paramter).

I really hope that I am not asking a silly question - If I am please point me in the right direction to some reading material, I don't know which subject I would need to start reading up on in the C language.

An answer to whether my 3 interpretations of the synatx are correct would be greatly appreciated :)

Many thanks & happy coding

Était-ce utile?

La solution

1) Yes, it's both a pointer and a function.

2) Yes, that's the syntax for declaring a function pointer.

3) Yes, that's a void pointer. They're very useful for passing memory addresses without a type.

Like was suggested by @user2485710 check out this tutorial on function pointers.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top