typedef struct foo{
void (*del)(void *toDel);
char* (*p)(void *tp)
} Foo;
Foo init(char* (*print)(void*),void (*delFunc)(void*));
Trying to figure out how to assign or initialize the supplied parameters to the struct function pointers.
Foo init(char* (*print)(void *toBePrinted),void (*delFunc)(void *toBeDeleted))
{
return Foo{ .del = delFunc, .p = print};
}
What about this? Long form:
Foo init(char* (*print)(void *toBePrinted),void (*delFunc)(void *toBeDeleted))
{
Foo tmp = {
.del = delFunc,
.p = print
};
return tmp;
}
How to initialize a struct in accordance with C programming language standards
You can do it the usual way:
Return (Foo){.del=delFunc, .p=print};
The straight forward (most backward compatible approach) to define foo
as Foo
and initialise it is:
Foo foo = { /* Mind the order of the following initialisers! */
delFunc,
print
};