0

I have a function int handle_request(server* server, int conn_fd); that takes in 2 arguments. How do I assign it to this function pointer? void (*func)(void* input, void* output)

I've been trying to do things like

void (*func)(void* input, void* output) = handle_request;

and tried these but I always get

warning: initialization from incompatible pointer type [enabled by default]

3
  • 2
    What does the prototype of handle_request look like? Commented Dec 18, 2013 at 9:11
  • 2
    The signature of handle_request needs to match your function pointer definition - perhaps you should post the definition of this too ? Commented Dec 18, 2013 at 9:12
  • 1
    handle_request function returns an integer and the function pointer that you have declared returns a void. Commented Dec 18, 2013 at 9:13

2 Answers 2

1

As mentionied in your question if the function prototype returns int, then the pointer must match it. If the retuzrn type should be void, then the pointer is also to be void.

void handle_request(void* input, void* output)
{
}

int main(int argc, _TCHAR* argv[])
{
    void (*func)(void* input, void* output) = handle_request;
    return 0;
}

or

int handle_request(void* input, void* output)
{
    return 0;
}

int main(int argc, _TCHAR* argv[])
{
    int (*func)(void* input, void* output) = handle_request;
    return 0;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Your function pointer should match your function signature. This means that you can assign function pointer:

void (*func)(void* input, void* output)

to the function:

void handle_request(void *input, void *output)

If you try to it your way a warning will be issued.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.