C - Variadic macro which expands into set of macro calls on each argument -


i want have single macro call takes in multiple function pointers, , each function pointer called second macro function declaration.

i want 2 macros on form

#define function_def(func) extern int func(void); #define function_defs(...) (???) 

which called such

function_defs(     myfunc1,     myfunc2,      otherfunc1,     otherfunc2,      defaultfunc ) 

which expands into

function_def(myfunc1) function_def(myfunc2)  function_def(otherfunc1) function_def(otherfunc2)  function_def(defaultfunc) 

in other words, single call function_defs expands function declarations of variadic arguments.

currently i'm skipping first step , calling function_def on each function pointer, solution great.

is possible?

edit:

thanks @vality introducing me x-macro. found post "real-world use of x-macros" needed.

i not believe want precisely possible using standard c preprocessor. similar solution can accomplished x macros.

to equivalent of code using them first define function list x macro:

#define function_list_a \     x(myfunc1) \     x(myfunc2) \     x(otherfunc1) \     x(otherfunc2) \     x(defaultfunc) 

then instantiate these functions specific macro define macro perform on each function:

#define x(name) function_def(name) function_list_a #undef x 

which expand to:

function_def(myfunc1) function_def(myfunc2) function_def(otherfunc1) function_def(otherfunc2) function_def(defaultfunc) 

hopefully useful , close want. admittedly syntax different if wish accomplish apply chosen function or macro whole list of data (in case function pointers) idiomatic way know of using c preprocessor.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

wso2esb - How to concatenate JSON array values in WSO2 ESB? -