I want to declare a constant array of constant char arrays. If I write it like this:
const char foo[] = "Foo";
const char bar[] = "Bar";
const char* const foobar[2] = { foo, bar };
It seems to work, but if I try to read it using "the spiral rule", foobar is read as:
"foobar is an array 2 of constant (??) to a pointer to a char constant"
Using this stack overflow answer,
const applies to the thing left of it. If there is nothing on the left then it applies to the thing right of it.
the first const
would apply to the char, and the second const
would apply to same char as well.
Both ways of reading it doesn't make sense, but the code does function (in Arduino [sorry], at least). Which const
is making which a constant? Is there a more logical way to write it?