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]

Community
  • 1
  • 1
StarShire
  • 189
  • 2
  • 10
  • 2
    What does the prototype of `handle_request` look like? – Austin Brunkhorst Dec 18 '13 at 09:11
  • 2
    The signature of `handle_request` needs to match your function pointer definition - perhaps you should post the definition of this too ? – Paul R Dec 18 '13 at 09:12
  • 1
    handle_request function returns an `integer` and the function pointer that you have declared returns a `void`. –  Dec 18 '13 at 09:13

2 Answers2

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;
}
Devolus
  • 21,661
  • 13
  • 66
  • 113
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.

nikpel7
  • 656
  • 4
  • 11