The struct boxis defined in box.h as such:
typedef struct box {
int (*func1) (const void *p1, const void *p2);
void (*func2) (void *p3);
} Box;
box.c includes box.h and has the following function:
int create_box(int (*func1)(const void *p1, const void *p2), void (*func2)(const void *p3), Box **box) {
create_box is called to initialize a box based on the provided parameters. I'm struggling to figure out how to assign the provided function pointers to the fields of the structure. First, I start out by allocating memory to **box via (*box) = malloc(sizeof(Box));
But then I try to assign the arguments of the function pointer through
(*box)->func1 = (func1)(&p1, &p2);
(*box)->func2 = (func2)(&p3);
Running this tells me that all of my pointers are undeclared. Clearly there's something I'm misunderstanding about how function pointers work, but I don't understand how I'm supposed to initialize them (if that's the write word). I've tried replacing the right side with (*func1)(*p1, *p2), (func1)(p1, p2), (*func1)(p1, p2), (*func1)(&p1, &p2), etc. but they haven't yielded anything that I can understand. How do I properly initialize this structure's function pointers?
I'm working in C90 if that's relevant.
(*box)->func1 = func1;?p1andp2in type declaration are not needed. I meanint (*func1)(const void*p1, const void *p2)means the same asint (*func1)(const void*, const void *).