How can I ensure COLOR_NAMES is filled to the correct size at compile-time? If a new color is added, say COLOR_4 (and hence N_COLORS is auto incremented), the compiler will then tell me COLOR_NAMES is not filled to size.
Most answers that I found online is for runtime, not compile time.
This is for C-style notation (no STL and other libraries usage).
enum Colors
{
COLOR_1,
COLOR_2,
COLOR_3,
N_COLORS;
};
const char* COLOR_NAMES[N_COLORS] =
{
/* COLOR_1 */ "Color1",
/* COLOR_2 */ "Color2",
/* COLOR_3 */ "Color3"
};
const char* Blah()
{
Colors color;
...
printf("%s blah blah\n", COLOR_NAMES(color));
}