I have a struct which has a function pointer as a member variable. The function pointer takes a pointer to the struct as one of its parameters.
By looking at solutions posted on here for such circular dependencies I used a forward declaration to be able to compile.
I still have the problem of not being able to initialize the struct. Posted below is the code and the output.
edit: My earlier MVCE didn't reproduce the problem correctly. I can get this to compile by naming the struct instead of just having a struct alias. Not exactly sure why though.
#include "stdio.h"
//Forward declaration
struct data;
typedef int(*funcPtr) (struct data* a);
typedef struct
{
int a;
int b;
funcPtr foo;
}data;
int foo(data* pData)
{
return 0;
}
static data testData[] = {{1,1,foo}, {0,2,foo},};
int main()
{
printf("Just trying to compile this program\n");
return 0;
}
Error output --
compileError.c:20:1: warning: initialization from incompatible pointer type [enabled by default]
static data testData[] = {{1,1,foo}, {0,2,foo},};
^
compileError.c:20:1: warning: (near initialization for \u2018testData[0].foo\u2019) [enabled by default]
compileError.c:20:1: warning: initialization from incompatible pointer type [enabled by default]
compileError.c:20:1: warning: (near initialization for \u2018testData[1].foo\u2019) [enabled by default