I usually use enums to keep two arrays consistent by defining them like following:
enum foo {
ZERO = 0,
ONE,
TWO,
};
int int_array[] = {
[ZERO] = 0,
[ONE] = 1,
[TWO] = 2
};
char *str_array[] = {
[ZERO] = "ZERO",
[ONE] = "ONE",
[TWO] = "TWO"
};
This code compiles fine for c
, but throws following error when used in a cpp
module.
expected primary-expression before ‘[’ token
Error is for each line in both array declarations. What's the problem here?