Thursday, 5 September 2013

Enum-based static array: C header

Enum-based static array: C header

I have an enumeration of values in a C header file. I want to define an
additional array or group of values, where each value corresponds to one
of the enumeration values. Essentially, the array would be a lookup table
for some information pertinent to each enumerated value. However, I want
to do this at compile time in a header file.
What is a good way to accomplish this?
Here is an example of how to accomplish it using two separate enumerations
or definition structs. Is there a more elegant way to accomplish this
using only the op enums?
enum op { op1, op2, op3 };
enum op_information { op1_info = 0xff, op2_info = 0xf3, op3_info = 0xc1 }

No comments:

Post a Comment