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.
Not sure whether X macros are the solution here. You can, however, use a bit of preprocessor magic to reduce the typing. The problem remains the conditional compilation (
#ifdefs) in your example. Without knowing what these conditions look like it is difficult to reduce the amount of typing further.Condider the following:
This is, I think, a step in the direction you are aiming for. To see what this does, you can try
(if you are on some Unix) or
(if you are on Windows using Visual Studio).