Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is void(*)(void *) [duplicate]

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)) 
{
...

...
}
like image 750
DeepBlack Avatar asked Oct 11 '12 01:10

DeepBlack


People also ask

What is void * in C?

The void pointer in C is a pointer that is not associated with any data types. It points to some data location in the storage. This means that it points to the address of variables. It is also called the general purpose pointer. In C, malloc() and calloc() functions return void * or generic pointers.

What does void * func () mean?

Void as a Function Return TypeThe void function accomplishes its task and then returns control to the caller. The void function call is a stand-alone statement. For example, a function that prints a message doesn't return a value. The code in C++ takes the form: void printmessage ( )

What is void * ptr C++?

A void pointer in C++ is a special pointer that can point to objects of any data type. In other words, a void pointer is a general purpose pointer that can store the address of any data type, and it can be typecasted to any type. A void pointer is not associated with any particular data type.

What is void in Objective C?

The (void) indicates the return type. This method doesn't return anything, so its result can't be assigned to anything.


2 Answers

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.

like image 99
Ed S. Avatar answered Nov 03 '22 10:11

Ed S.


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.

like image 34
bobestm Avatar answered Nov 03 '22 09:11

bobestm