Let's say we have two structs in a source file:
struct B {
int x;
};
struct A {
beta y;
};
In the equivalent header file we have these:
typedef B* beta;
typedef A* alpha;
Also, these function prototypes are defined at the header file:
printAplha(alpha);
compare(const beta, const beta);
In the main file, I have included the specific header file and the code looks like this:
alpha one, two;
printAlpha(one);
printAlpha(two);
//everything works fine up to here
compare(one->y, two->y);
At the last line of the code I am getting
main.c:37:20: error: dereferencing pointer to incomplete type
main.c:37:33: error: dereferencing pointer to incomplete type
I know I can use a wrapper function for compare
, the arguments of which would be of type alpha
(as the arguments of the compare function cannot be changed - it's a recursive one), but I would like to see if there is any other solution, and why is this happening.
Note: The struct definitions have been written into the source file for creating an opaque data type.