I have an array of strings (char*
). For example:
char* strings[] =
{
"abc",
"def",
"ghi"
};
To best refer to them by their index, I need to create a separate enum:
typedef enum
{
abc = 0,
def,
ghi
} enum_strings_t;
Assuming I often need to add new entries, I need to do it in 2 places- the strings
array and enum_strings_t
enum- need to manually keep them in sync.
My question is: can this be somehow fixed by a macro, meaning, that only 1 new entry (instead of 2) would update both the enum and the array? I am looking for a native way of doing this in C, without using external Python scripts that would manually edit the header file.