The type of func2
is - int (struct test *)
and you are passing func2
pointer as 2nd argument to func1()
whose 2nd parameter type is int (*)(struct test)
. This is type mismatch. You need to make correction in 2nd parameter type of func1()
function:
void func1( struct test *test_func1, int (*f)(struct test *))
^^^
The parameter type of func2()
function is - struct test *
. That means, it can receive address of variable of type struct test
. Here,
// calling function
(*f)(*test_func1);
pointer f
hold the address of func2()
function and argument that you are passing is of type struct test
. Again the type mismatch. Instead, it should be
// calling function
(*f)(test_func1);
^^^
because the test_func1
is of type struct test *
which is same as the type of parameter of func2()
function.
One more point, you don't need to give &
with test_func2->in
when printing its value in func2()
function:
printf("Inside func2, msg is : %s
", test_func2->in);
^^^
Same is for func1()
function when printing test_func1->in
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…