I frequently use enum
in C to access array elemnets with numerical data, e.g.
#define KEYS_MAX 1
#define FIELD_MAX 2
enum {FIELD1=0, FIELD2};
double array[KEYS_MAX][FIELD_MAX];
array[1][FIELD1] = 1.0; array[1][FIELD2] = 2.0;
I then print the data to a file in KEYS_MAX
lines and FIELD_MAX
columns. To know later the content of the columns I would like to print a header line.
# KEY FIELD1 FIELD2
1 1.0 2.0
I would like to have a routine which does this during runtime correctly even if I update the code by changing only enum
. I.e., how can I print the header line using C-code and possibly macros using a fixed routine independent of updates of enum
?
I found this: Mapping enum values to strings in C++ , but I would prefer something which would also work with the intel compiler.