> I like your code example, but it might only work in C (not C++).
Sorry, you are confused. It works in both C++ and C.
> Using the enum value as an array index might give unpredictable results
> since C++ treats enumerations as a distinct type (instead of int as in C)1
Nope.
Here the enum is promoted to an integer. C++, like C, promotes a lot of types to integers under the right situations.
> The C++ standard library string can have '\0' characters anywhere inside
> the string (which may also lead to unpredictable behavior at runtime)2. Of
> course, you're referring to a C-style string, so this may be a moot point.
There is no std::string in this example. You are confused.