I have a struct which is defined like this:
typedef struct {
sn74lvc138a_options_t decoder_opts;
uint32_t pin_int;
uint32_t pin_rst;
uint32_t pin_pwr;
...
} w5500_options_t;
The nested struct sn74lvc138a_options_t struct looks like this:
static const sn74lvc138a_options_t sn74lvc138a_opts ={
.decoder_a = DECODER_A_GPIO,
.decoder_b = DECODER_B_GPIO,
.decoder_c = DECODER_C_GPIO,
.decoder_sel = DECODER_SEL_GPIO
};
These two are stored in two different C modules. One of the C modules (the one which also contains the w5500_options_t instance) has the following function defined:
static const sn74lvc138a_options_t* _get_spi_decoder(void) {
return cpu_samv71_get_sn74lvc138a(); // This is a function from the other C module
}
I would like to be able to do the following for compile time initialization:
static const w5500_options_t w5500_opts = {
.pin_int = SOMEVALUE1,
.pin_rst = SOMEVALUE2,
.pin_pwr = SOMEVALUE3,
.decoder_opts = _get_spi_decoder()
};
Basically what I'm trying to do, is to get a reference to a struct instance inside an initialization block. Since the reference itself is defined as const and the function returns a const pointer the compiler should be able to do this (I'm using GCC with C99).
The question is now: Is this not allowed at all or am I doing something wrong which disallows this. The exact error message I get from the compiler is that the "initializer element is not constant".