Now that I found a way to statically initialize my array of items, I need a more complexe structure and instead of a char* as a value, I need a struct (named atom_s).
typdef struct atom_s {
const char *val;
const char *filter;
} atom_t;
struct
{
const char *key;
const atom_t **values;
} key_to_values[] =
{
{ .key = "foo", .values = (const atom_t *[]) { NULL } },
{ .key = "bar", .values = (const atom_t *[]) { { .val = "foo", .filter = "bar" }, NULL } },
};
The problem is: I don’t know how to initialize an atom_s inside the array declaration above or if it is even possible.
The second line of the array (with key = “bar”) does not compile:
warning: braces around scalar initializer
warning: (near initialization for '(anonymous)[0]')
error: field name not in record or union initializer
Each element of the array pointed to by
values, points to an array ofatom_t(except the last, which is null). You might also need some way to terminate each of those inner arrays, unless they’re always the same length.