4 ms·
You can use an x-macro: // cmds.def X(1) X(2) X(3) X(4) #undef X // elsewhere.h enum { #define X(x) CMD##x = x - 1, #include "cmds.def"
by evincarofautumn 10y ago
You can use an x-macro:
// cmds.def
X(1)
X(2)
X(3)
X(4)
#undef X
// elsewhere.h
enum {
#define X(x) CMD##x = x - 1,
#include "cmds.def"
END_CMD
};
Or a higher-order macro:
#define CMD_LIST(X) X(1) X(2) X(3) X(4)
enum {
#define CMD(x) CMD##x = x - 1,
CMD_LIST(CMD)
#undef CMD
END_CMD
};