I want to generate a enum with a X-Macro. The enum has to increace based on prev size.
I have this
#define LIST
VAR(one, 0x02)
VAR(two, 0x02)
VAR(tree, 0x03)
and want to generate this
enum{
one = 0x02 + 0,
two = 0x02 + one,
tree = 0x03 + two
}
but this does not work
#define VAR(NAME, SIZE) STORED_LOCATION_##NAME = SIZE + (STORED_LOCATION_##NAME-1)
enum{STORED_VARIABLES};
#undef VAR
This works but i thing it can been easier
#define LIST \
VAR(one ) STR(STORED_LOCATION )\
VAR(two ) PRE(one )\
VAR(tree ) PRE(two )\
VAR(fore ) PRE(tree )\
enum
{
one = 0x00,
two = 0x01 + one,
tree = 0x01 + two,
fore = 0x01 + tree,
};
#define STR(OFFSET) OFFSET,
#define PRE(NAME) sizeof(##NAME) + STORED_LOCATION_##NAME,
#define VAR(NAME) STORED_LOCATION_##NAME =
enum{STORED_VARIABLES};
#undef VAR
#undef PRE
#undef STR