1

When I was browsing the Linux code I encountered the following snippet :

static void __init do_initcalls(void)
{
initcall_t *fn;

for (fn = __early_initcall_end; fn < __initcall_end; fn++)
    do_one_initcall(*fn);
}

initcall_t is a function pointer .

The prototype of do_initcalls is int do_one_initcall(initcall_t fn) .

So I thought invoking do_initcalls would be like do_one_initcall(fn) but I see it is do_one_initcall(*fn) . Why is that *fn instead of only fn??

3
  • Why did you think so? You said it yourself: do_one_initcall requires an argument of initcall_t type. Yet you somehow expect to pass a initcall_t * argument to it. Why? If it expects a initcall_t, you have to pass an initcall_t. That's all. There's no way to answer your question without understanding what strange logic made you ask it. Why would yo want to pass a initcall_t * to a function that expects a initcall_t? Oct 16, 2011 at 14:31
  • 2
    @nc3b: I upvoted it to compensate for the downvote. Since the question is clearly expressed and well-formatted, I see no reason for downvoting. Being confused or not knowing something is the whole purpose of asking questions. Oct 16, 2011 at 14:46
  • @BlagovestBuyukliev Okay, that's sensible I guess.
    – nc3b
    Oct 16, 2011 at 14:48

1 Answer 1

4

Because initcall_t is itself defined as a function pointer, initcall_t *fn declares a pointer to a function pointer, and thus the * dereferencing operator is applied to get the function pointer.

Here is the definition of the initcall_t type:

typedef int (*initcall_t)(void);

So the type initcall_t is already a pointer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.