Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does an asterisk before a function name mean?

In the following lines of code, what does the asterisk in front of dup_func, free_func, and clear_free func, do?

void *(*dup_func)(void *);
void (*free_func)(void *);
void (*clear_free_func)(void *);
like image 933
Matt Avatar asked Jul 14 '11 13:07

Matt


1 Answers

In your examples it means they are function pointers.

In a nutshell, they allow you to do things like this:

void example()
{
    printf("Example called!\n");
}

void call_my_function(void (*fun)())
{
    printf("Calling some function\n");
    (*fun)();
}

/* Later. */
call_my_function(example); 
like image 67
cnicutar Avatar answered Sep 18 '22 01:09

cnicutar