Reputation: 819
I encountered the following line as a C function declaration. I'm confused by the type of the first argument passed in. Can anyone explain how to understand the type of the first argument?
int clone(void (*fcn) (void *) , void *arg, void *stack)
Upvotes: 1
Views: 1033
Reputation: 47814
Use "Spiral Rule" :
+------+
| +--+ |
| ^ | |
void (*fcn ) (void *)
^ ^ | |
| +----+ |
+----------+
So,
fcn
is a pointer tovoid *
as an argumentvoid
(nothing)Upvotes: 3
Reputation: 21460
After a few editing (to remove the names of variables) cdecl gave the answer:
declare clone as function (pointer to function (pointer to void) returning void, pointer to void, pointer to void) returning int
Or, you can test only the first argument and get it's type: pointer to function of pointer to void, returning void.
Upvotes: 1
Reputation: 122443
void (*fcn) (void *)
Read the type from inside out: fcn
is a pointer to a function, that function takes a void *
parameter and returns nothing (void
).
Upvotes: 4