Reputation: 657
I am reviewing some C code, but having a hard time understanding what Callback is exactly. Does anyone know what this means? I'm guessing that it is defining "Callback and x to be both a void *?
typedef void (*Callback)(bool x);
Upvotes: 1
Views: 166
Reputation: 182734
It makes a new type name Callback
. Every Callback
will be a pointer to a function taking a bool
and returning void
. In effect Callback
will be an alias for that real type. So when you say:
Callback ptr = some_fun;
You're making a function pointer that points at some_fun
. Function pointers are typically passed to other functions as arguments.
Upvotes: 5
Reputation: 206616
It declares a function pointer type by the name Callback
which points to a function which takes a bool
input parameter and returns a void
.
Once you specify the statement, You can use Callback
as a type to hold address of a function with the specifed type.
Refer the Clockwise spiral rule when in doubt.
Upvotes: 2