What is void(*)(void *) [duplicate] - c++

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
What does “void *(*)(void *)” mean in c++?
What does the type void(*)(void *) mean?
I came across this type in the example code for the book "Mastering Algorithms with C"
void list_init(List *list, void (*destroy)(void *data))
{
...
...
}

It's a function pointer.
void (*destroy)(void *data)
destroy is a pointer to a function which returns void and takes a void* as an argument.
cdecl.org is a useful tool for discerning complex C declarations. Also, take a look at the spiral rule.

In this specific case, its a pointer to which any function can be cast to void(*)(void *) and the function parameter void * can be any type.

Related

C++ what is the difference of type * and type *& in function [duplicate]

This question already has answers here:
Passing references to pointers in C++
(10 answers)
Closed 4 years ago.
I have two function signatures in C++
void printArray(int* arrayPtr);
void printArray(int*& arrayPtr);
I understand the 1st function. It says the function takes in a arrayPtr argument which is of type that's a pointer pointing to an integer.
Both function signature works, but I have a hard time understanding the 2nd signature(*&) and what benefits it offers?
It's exactly the same as type versus type&; the first is a value and the second is a reference. The fact that type is a pointer doesn't change that.

What is the syntax in this typedef statement doing? [duplicate]

This question already has answers here:
Typedef function pointer?
(6 answers)
Closed 6 years ago.
I ran across a line of code that looks like the following:
typedef Foo* (*CREATE_BAR)(uint32_t);
How exactly does this work? What is happening in this code?
It's a function pointer type named CREATE_BAR which accepts a uint32_t argument and returns a Foo*. It could hold a pointer to any such function.
It is a type for a pointer on function returning Foo*, and taking uint32_t
In c++11, it would be
using CREATE_BAR = Foo* (*)(uint32_t);

What does "void f(int (*)[7]) {}" mean? [duplicate]

This question already has answers here:
what does this mean char (*(*a[4])())[5]?
(4 answers)
Closed 7 years ago.
Can somebody explain what does it mean?
void f(int (*)[7]) {}
There is a site devoted to dealing with C gibberish and converting it to English:
cdecl.org Try it) It is convenient and sometimes even entertaining.
It states that void f(int (*)[7]) means: declare f as function (pointer to array 7 of int) returning void.
This is a function definition, which can accept a pointer to an array of int with 7 size.
Declare an 7-size array, int a[7];, and you can pass the address of it into f, like f(&a);
Check the live: http://cpp.sh/8ztz
It's definition of function that takes one parameter. That parameter is an unnamed pointer to array of ints.

*& Pointer in C program [duplicate]

This question already has answers here:
What does `*&` in a function declaration mean?
(8 answers)
Closed 8 years ago.
I am Converting a C++ code into C program. I come across a function that takes void draw(char *&a). how to write this function *& in C program. I tried using same *&a but it is showing , (...etc expected. Please help.
Thanks
There is no pass by reference in C. Therefore you need to change the function declaration to
void draw(char **a)

What's the difference between fun(...) and (*fun)(...) using a function pointer in C/C++ [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How come pointer to a function be called without dereferencing?
How does dereferencing of a function pointer happen?
Supposing I have a function pointer like:
void fun() { /* ... */ };
typedef void (* func_t)();
func_t fp = fun;
Then I can invoke it by:
fp();
or
(*fp)();
What is the difference/
Precisely two parentheses and an asterisk.
Both call the function pointed to by fun, and both do so in the same manner.
However, visually, (*fun) makes it clear that fun is not a function in and of itself, and the dereference operator is a visual cue that it is a pointer of some kind.
The without-parentheses syntax, fun(), is the same as a regular function call and so visually equates to that, making it primarily clear you're calling some kind of function. It takes context or a lookup to notice that it is a function pointer.
This is just a style difference, as far as what happens.