C Language
Macros
Tricks
Macro callback pattern for list of things
#define LIST_OF_THINGS(DO) \
DO(ITEM_0) \
DO(ITEM_1) \
DO(ITEM_2) \
DO(ITEM_3) \
DO(ITEM_4) \
DO(ITEM_5) \
DO(ITEM_MAX)
typedef enum enumname {
#define DECL_ENUM(item) item,
LIST_OF_THINGS(DECL_ENUM)
#undef DECL_ENUM
} enumname_t;
const char* enumname_strings[] = {
#define DECL_S(it) #it,
LIST_OF_THINGS(DECL_S)
#undef DECL_S
};