Hi, I spent some time recently learning D. I am curious about the best way to implement something like X-includes in C. I.e. where one use macros that you redefine at the include point.

This is indispensable sometimes for keeping code in sync.

For example, if we in an include header writes:

---
#ifndef X
#define X(a, b)
#endif

X(int, foo)

#undef X
---

We can then include it as follows (this probably won't compile, but should serve as an illustration):

// Define the globals
#define X(a, b) a b;
#include "blah.inc"

struct {char *, void *} myarray[] = {
#define X(a, b) {#b, &b} , // C99 allows for comma at the end
#include "blah.inc"
};

The point here is that we can make a single point definition of something which is then later used in multiple locations in order to keep things in sync.

So my question is, whether there is some clever way to use mixins and templates that accomplish roughly the same thing of defining a table at one location and then reusing the table at multiple locations for different purposes?

Reply via email to