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??
Because
initcall_tis itself defined as a function pointer,initcall_t *fndeclares 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_ttype:So the type
initcall_tis already a pointer.