#include <stdio.h>
struct context;
struct funcptrs{
void (*func0)(context *ctx);
void (*func1)(void);
};
struct context{
funcptrs fps;
};
void func1 (void) { printf( "1\n" ); }
void func0 (context *ctx) { printf( "0\n" ); }
void getContext(context *con){
con=?; // please fill this with a dummy example so that I can get this working. Thanks.
}
int main(int argc, char *argv[]){
funcptrs funcs = { func0, func1 };
context *c;
getContext(c);
c->fps.func0(c);
getchar();
return 0;
}
I am missing something here. Please help me fix this. Thanks.
Try this
A struct (without a typedef) often needs to (or should) be with the keyword struct when used.
If you typedef your struct you can leave out the struct keyword.
Note that it is legal to reuse the struct name
Try changing the forward declaration to this in your code:
It might be more readable to do add a suffix to indicate struct name and type name: