Macro-producing macros in C?

c, c-preprocessor, macros, variadic-functions

Solution

It's not possible in standard C.

Problem

I'd like to get the C preprocessor to generate macros for me (i.e., I'm using C99 only). I'd write a macro ``` #define make_macro(in) <...magic here...> ``` and when I put ``` make_macro(name1) make_macro(name2) ``` later in the code, it would expand to ``` #define name1(...) name1_fn(name1_info, __VA_ARGS__) #define name2(...) name2_fn(name2_info, __VA_ARGS__) ``` and I'd then be able to use name1 and name2 as (macro-implemented) functions. I think I'm stuck using macros at both steps: it makes sense to use a macro to repeatedly re-fill a template, and the variadic argument handling won't work except via a macro. So what goes into the <...magic here...> placeholder to do this? At this point, I'm starting to believe that it's not possible in C99, but perhaps I'm missing some details of syntax.

Original source