C preprocessor init array -


i'm writing complex macro , need pass array initializer. have trouble do:

#define init_arr(var_name,arr_data) int var_name[] = arr_data 

then call

init_arr(mynm,{1,2,3}); 

but preprocessors interprets commas (also 1 inside curly braces) new macro parameter gives me error:

error:  #55-d: many arguments in invocation of macro "init_arr"  

preprocessor not ignore () can do:

#define init_arr(var_name,arr_data) int var_name[] = {arr_data} init_arr(mynm,(1,2,3)); 

but interpreted

int mynm[] = {(1,2,3)}; 

which not correct c.

is there way how it?? example remove braces parameter?

i think cracked it:

#define myargs(...) __va_args__ #define init_arr(var_name,arr_data) int var_name[] = {myargs arr_data} init_arr(myarr,(1,2,3,4)); 

will interpreted correctly as:

int myarr[] = {1,2,3,4}; 

annoying_squid's answer helped me figure out...


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -