I have 2 files file1.c file2.c. I need to store the Function Pointers passed from file1.c to file2.c in a struct array of size 2.
file1.c
main ()
{
setFuncPointer ( 1, &call_to_routine_1 );
setFuncPointer ( 2, &call_to_routine_2 );
void call_to_routine_1 ()
{
// Do something
}
void call_to_routine_2()
{
// Do something
}
}
file2.c
struct store_func
{
UINT32 Id;
void *fn_ptr;
} func[2];
void setFuncPointer( UINT32 id, void(*cal_fun)())
{
func[0].id = id;
/* How to assign the cal_fun to the local fn_ptr and use that later in the code */
}
Also, I am unsure of declaring the void pointer inside the struct. Please suggest the right way of defining and using the callback functions defined in file1.c from file2.c
Thanks in advance
void *is undefined behaviour. Us the correct type for the pointers.