I'm trying to write the equivalent of an enum in C++ going in steps of eight instead of one, like
enum
{
foo,
bar = 8,
baz = 16,
};
There will be a lot of entries, new ones will be added at intervals, and for clarity they really want to be written in an order other than order of entry, so it would be nice not to have to keep updating all the numbers by hand. I've tried mucking around with macro preprocessor tricks, but no dice so far. Is there a way to do this that I'm overlooking?
#define NEXT_ENUM_MEMBER(NAME) \
NAME##_dummy, \
NAME = NAME##_dummy - 1 + 8
enum MyEnum {
Foo,
NEXT_ENUM_MEMBER(Bar),
NEXT_ENUM_MEMBER(Baz),
...
};
I prefer something like this:
enum {
foo = (0 << 3),
bar = (1 << 3),
baz = (2 << 3),
};
It's not automated, but it doesn't require much thinking when adding a new enum constant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With