The author tried using __COUNTER__ and a static array of function pointers, and narrowly missed a workable idea—a static linked list! Forward declarations pun definitions, and can be used roughly as follows:
struct Element {
int value;
struct Element *next;
}
#define ELEMENT(value) _ELEMENT(value, __COUNTER__)
#define _ELEMENT(value, n) \
struct Element CAT(e, SUCC(n)); \
struct Element CAT(e, n) = { (value), &CAT(e, SUCC(n)) }
You can then walk from e0 through the linked list, but because of how the initialization works, you're done when the current element has `next == 0`.
int main(void)
{
struct Element *e = &e0;
while (e->next) {
printf("%d\n", e->value);
e = e->next;
}
}
Here's a repl.it:
https://repl.it/repls/DetailedYoungAsianconstablebutterfly