I am trying to create a table of elements (structs) where each element contains a dynamic list of enums in C. However, it seems this is not possible in C as I keep getting the following error:
error: initialization of flexible array member in a nested context
Here is a small sample of my code:
#include <stdio.h>
#include <stdint.h>
typedef enum {
NET_0 = 0,
NET_1,
NET_2,
TOTAL_NETS,
} net_t;
typedef struct {
uint8_t num_nets;
net_t net_list[];
} sig_to_net_t;
sig_to_net_t SIG_NET_MAPPING[] = {
{1, {NET_0}},
{2, {NET_1, NET_2}},
{1, {NET_2}},
};
Any solution for this issue in C?
FYI, the only solution I found would be to replace the dynamic array net_list with a fixed-size array. However, this solution is not optimal as this code will be flashed on memory-limited devices and I have cases where the net_list will contain 5 elements which are only a few cases out of 1000 entries in the SIG_NET_MAPPING table.