I am learning C language and while learning I found a line of code which is totally new and strange for me
void PullDown(char **, int, void (__cdecl **)(void));
I know about 1st and 2nd parameter only .
I want to know about 3rd parameter.
what's is the use of two asterisk after __cdecl ?
I am aware from this syntax (type_cast *)
so it is related to type casting ?
The 3rd parameter is pointer to function pointer. With only one asterix, it would be function pointer.
__cdecl
is a compiler specific attribute that indicates that C calling convention must be used. See this page. If you play only with C or with other compiler, then you may ignore it.
Maybe example is helpful:
#include <stdio.h>
void PullDown(char **, int, void (**)(void));
int main(int argc, char **argv)
{
void (*fun)(void);
PullDown(NULL, 0, &fun);
fun();
return 0;
}
void my_function(void)
{
printf("Hello!\n");
}
void PullDown(char **param1, int param2, void (**param3)(void))
{
*param3 = my_function;
}
It prints "Hello!"
In the example, fun
is a function pointer variable. Pointer of fun
is passed to the PullDown()
function call. So PullDown()
can set pointer of my_function()
to the fun
.