Complete noob to C, just getting started with some goofing around, wondering how (read "if") the following is possible.
Trying to create a struct, with a member that is a function pointer, and the function pointer points to a function that takes an argument with the same type as the aforementioned struct. For example (mind the syntax, just getting familiar here):
typedef struct{
void (*myStructFunc)(void);
} MyStructType;
void myFunc(void){
printf("Hello world!");
}
// ...
MyStructType myStruct;
myStruct.myStructFunc = &myFunc;
myStruct.myStructFunc(); // <= Hello world!
This works fine, but when I try to introduce arguments of the MyStructType type to the function:
typedef struct{
void (*myStructFunc)(*MyStructType); // <= parse error
} MyStructType;
void myFunc(MyStructType *myStruct){
printf("Hello world!");
}
// ...
MyStructType myStruct;
myStruct.myStructFunc = &myFunc;
myStruct.myStructFunc(&myStruct);
These examples are brief for obvious reasons, but they illustrate my intentions. Again, just getting my feet wet with C so please forgive any syntactical ignorance.
Anyways, how can I achieve this? Clearly I'm doing something incorrect syntactically, or perhaps I'm trying to do something that's plain not possible.
Also note, that the reason for this is purely academic.