Описание тега x-macros
Using macros to use the same tokens in multiple ways.
X-Macros are a use of the c-preprocessor to use the same tokens in different patterns.
They either use #include
s or additional macros for the input to transform:
#define MAPPING X(0, 55 do_a) X(1, 42, do_b) X(23, 7, do_c)
// Sometime later:
switch(expr) {
#define X(a, b, c) case a: return b + c(a, b);
MAPPING
#undef X
default:
abort();
}
Or maybe:
switch(expr) {
#define X(a, b, c) case a: return b + c(a, b);
#include "mapping.inc"
#undef X
default:
abort();
}
Why use X
?
It's extremely short, and unlikely to already be #define
-d.