I want to statically initialize an array, but some of its element are pointer to extern struct.
I can't declare the struct as constant, as their element are modified elsewhere, neither static as it clash with extern declaration.
Is there a way to solve this in the static array initialization, or i have to initialize it in a function?
EDIT:
looking at your examples after a great launch I just found the error was i was using PWMD2 instead of &PWMD2 (where PWMD2 is the external struct).
Obviously the error was
error: initializer element is not constant
Just to point out what i am doing, the partial of the code (using ChibiOS) is the following:
esc.h
extern struct Engine{
GPIO_TypeDef *gpio;
uint8_t pin;
PWMDriver *driver;
pwmchannel_t channel;
pwmcnt_t width;
}engines[];
esc.c
struct Engine engines[] = {
{GPIOD, 3, &PWMD2, 0, 0},
{GPIOD, 4, &PWMD2, 1, 0},
{GPIOD, 6, &PWMD2, 2, 0},
{GPIOD, 7, &PWMD2, 3, 0},
};