I'm working in C on an embedded microcontroller and am attempting to declare and initialize (in ROM) a const struct with an array of const structs, as demonstrated by this extremely simplified example:
typedef struct s_test TestStruct;
struct s_test {
char c;
int const * const ptr;
};
TestStruct const test1 = { 'a', NULL };
TestStruct const test2 = { 'a', (const int const []){ 2, 3, NULL } };
Instance test1 occupies ROM as expected, while in the case of instance test2, the child array ends up in RAM (not ROM, as intended).
If I declare an intermediate array, then use the reference to that array, the structure and array instances occupy ROM as expected...
int const array1[] = { 1, 2, NULL };
TestStruct const test3 = { '1', array1 };
Why, when I declare and initialize the array within the structure initialization, does the child array get stored in RAM instead of ROM? Perhaps my syntax is incorrect? Is there a successful way to do this? It would make for so much more readable data structure declaration and initialization, rather than having to forward-declare all the intermediate child arrays. Initially I thought I was so clever declaring my data structure, but then was sorely disappointed to find it was largely occupying RAM. :\
struct s_test {char c; int list[];}, so that thelistis contiguous with the struct?