, , , :
, , , switch, ..
, include, , :
enum(INITIAL_STATE, 0, "This is the initial state")
enum(FLAG_READ, 1, "We have read the flag symbol")
...
, :
struct enum MyEnum {
#define enum(val,ix, string) val,
#include "myenumdef.i"
#undef enum
};
char *MyEnumStrings[] = {
#define enum(val,ix, string) string,
#include "myenumdef.i"
#undef enum
};
char *MyEnumNames[] = {
#define enum(val, ix, string) #val,
#include "myenumdef.i"
#undef enum
};
struct myEnumDesc {
int e_val;
int e_ix;
char *e_name;
char *e_desc;
} enum_table[] = {
#define enum(val,ix,string) val, ix, #val, string,
#include "myenumdef.i"
#undef enum
};
switch(val) {
#define enum(val,ix,string) case VAL_##val: return string"("#val"="#ix")";
#include "myenumdef.i"
#undef enum
default: return "invalid val";
}
C, , C.
, ( ), enum ( , ), . , .i, , , .
C-only , , .