I'm currently working on a dictionary library in C and would like to start using struct's for easy assignment. Now, I have several functions that need to be a member in said struct's. I have it working well using pointers, but my only problem is that I would like to not have to assign the function to the pointer in every instance. For instance;
int func(int a)
{
return a;
}
int main()
{
struct foo
{
int (*func)(int)
};
struct foo bar;
bar.func = func; /* This is the part I'd like to get rid of. I'd like it to just be '
bar.func(4), for instance' */
bar.func(4);
return 0;
}
So is it possible to assign the struct pointer _to_ the function? Or does it have to be assigned after the new variable is initialized? I'm not exactly too sure on how to go about that, so anything would help!
Thanks!