Assuming my code looks like in the following snippet:
#ifdef COND1
extern int func1(void);
#endif
...
#ifdef CONDN
extern int funcn(void);
#endif
my_struct funcs[] = {
#ifdef COND1
{"func1 description", func1},
#endif
...
#ifdef CONDN
{"funcn description", funcn},
#endif
{NULL, NULL},
};
Is it possible to replace this with X macros in order to minimize the repetition of the function names and conditions in both parts?
Without the #ifdef CONDX
conditions, this appears to be quite straight forward. However, I have no idea how to include them in the X macro, because it is not allowed to use #ifdef
in a #define
.
Suppose you want to define COND1 but no CONDN. I think you can do the following:
The problem is that you need to define all of the macros, but with different expansions.