Suppose I have a function called
void funct2(int a) {
}
void funct(int a, (void)(*funct2)(int a)) {
;
}
what is the proper way to call this function? What do I need to setup to get it to work?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Normally, for readability’s sake, you use a typedef to define the custom type like so:
when defining this typedef you want the returning argument type for the function prototypes you’ll be pointing to, to lead the typedef identifier (in this case the void type) and the prototype arguments to follow it (in this case “int args”).
When using this typedef as an argument for another function, you would define your function like so (this typedef can be used almost exactly like any other object type):
and then used like a normal function, like so:
So an entire code example would look like this:
and would print out: