3 ms·
In practice it is written like like this: #define MY_ENUM(x) x(MY_A) x(MY_B) x(MY_C) enum my_enum { MY_ENUM(ENUM_ENTRIES) }; static const char *my_enum_
by uecker 5mo ago
In practice it is written like like this:
#define MY_ENUM(x) x(MY_A) x(MY_B) x(MY_C)
enum my_enum { MY_ENUM(ENUM_ENTRIES) };
static const char *my_enum_names[] = { MY_ENUM(ENUM_NAMES) };
but one could also make it even more compact if one cared.
- spacechild1 5mo agoThat doesn't look any better. Yes, xmacros have the best compile times, but you can't possibly argue that they are elegant to use compared to the alternatives.
- uecker 5mo agoIt looks better to me than the other macro solution as it is more transparent what is done compared to DEFINE_ENUM. But I agree it is not as succinct as C++'s reflection syntax.
- spacechild1 5mo ago> It looks better to me than the other macro solution as it is more transparent what is done compared to DEFINE_ENUM. Fair enough.