I am getting "initializer element is not constant" while compiling following program.
In my source I want to keep list of all objects. I have created same scenario in the following program. Can you please help me to understand what went wrong with the following program.
Code:
struct ex_attribute {
void (*fn1)(int);
void (*fn2)(int, int);
};
void one(int a) { return; }
void two(int a,int b) { return; }
void three(int a) { return; }
void four(int a, int b) { return; }
int main()
{
struct ex_attribute one1 = {
.fn1 = one,
.fn2 = two,
};
struct ex_attribute two2 = {
.fn1 = three,
.fn2 = four,
};
static struct ex_attribute total_attrs[] = {
one1,
two2,
};
return 0;
}
I also tried with array of structure pointers also as shown below but still I am getting the same error while compiling.
Code:
static struct ex_attribute *total_attrs[] = {
&one1,
&two2,
};