C: Passing a function pointer to a function is passed to

I am trying to write a mapping function that takes a pointer to a function and passes it to another function, but gcc yells at me.

Here is the idea of ​​what I'm trying to do.

void map(T thing, void apply(int a, int b, void *cl), void *cl);

void function(T thing, void apply(int a, int b, void *cl), void * cl)
{

   for(int i = 0; i < 10; i++)
   {

      map(thing, apply, cl);

   }

}

gcc complaint:

warning: passing argument 2 of 'map' from an incompatible pointer type

Any ideas?

+3
source share
4 answers

To help with this problem, we will need to see the declaration / signature of the display function. There is almost certainly a slight difference in the signature of the function. The easiest way to enable this is to print the type of the function pointer and use it in both functions.

typedef void (*apply)(int,int,void*);
+4
source

. .

void map(T thing, void (*apply)(int a, int b, void *cl), void *cl);
void function(T thing, void (*apply)(int a, int b, void *cl), void * cl)
{
    /* ... */
    map(thing, apply, cl);
    /* .... */
}
+2

, , map, apply. , ( ), .

0

gcc 4.3.3 -Wall.

, C, - , "" , :

void function(T thing, void (*f)(int a, int b, void *cl), void * cl)

, , , , typedef int T map(1, ...)

0

Source: https://habr.com/ru/post/1719182/


All Articles