I have the following constant struct which holds function pointers:
/* module1.h */
typedef struct my_struct my_struct_t;
struct my_struct
{
void (*funcPtr1)(void);
void (*funcPtr2)(void);
}
extern const my_struct_t myStruct1;
/* module1.c */
#include <module1.h>
static void func1(void)
{
// do something
}
static void func2(void)
{
// do something else
}
const my_struct_t myStruct1 = {
.funcPtr1 = &func1,
.funcPtr2 = &func2
}
So far so good!
Now I want to create a constant array of the above struct and assign the function pointers from instances of the struct:
/* module2.c */
#include <module1.h>
const my_struct_t arrayOfMyStruct[] = {
{ myStruct1.funcPtr1, myStruct1.funcPtr2 },
// ...
}
Compiler throws an error and says, that the expressions "myStruct1.funcPtr1"
and "myStruct1.funcPtr2"
were not constant.
What is wrong?