I have a constant lookup table
static const uint32_t lut [] = {0, 20, 100, 350, 560};
I have a struct
typedef struct {
uint32_t value;
const char * name;
} strct_t;
And I would like to create global constant instance of that struct
const struct_t def_myname = {
.value = lut[DEF_MYNAME_ID],
.name = "myname",
};
but I need to define DEF_MYNAME_ID
in other place, so I have this in some header file
#define DEF_MYNAME_ID 3
This can't compile, because of this error initializer element is not constant
There are multiple questions in stackoverflow asking what to do with initializer element is not constant
, but none covers my needs.
Is there a way how to do this? For example by defining lut
as macro? I don't need it in other place.
Is there something like
#define LUT(a) ...
usabele as const initializer?