Alright, so I'm trying the following:
// some function
void doSomething(void)
{
draw_text("Doing something",20,20,vector(255,255,255));
}
// some struct
typedef struct someStruct
{
void myFunction(void);
}someStruct;
someStruct* myStruct =
{
myFunction = doSomething;
}
// a main void
void main()
{
while(1)
{
if(key_j)
myStruct.myFunction();
wait(1);
}
}
So, obviously I'm trying to use a function pointer as a member of my struct to be able to have different instances of that struct calling different functions.
However, running this, first of all, I get a compiling error (wrong number/type of parameters) for my function call in the main function; If I replace
myStruct.myFunction();
with
myStruct.myFunction(NULL);
it compiles, however as I press "j" I get a "crash in main: SYS" error message.
So, now I'd like to know, how can I use function pointers as members of a struct, and how can I call these functions without crash?
Thanks in advance.