C preprocessor init array

Viewed 3840

I'm writing a complex macro and I need to pass also array initializer. Basically I have trouble to do:

#define INIT_ARR(VAR_NAME,ARR_DATA) int VAR_NAME[] = ARR_DATA

then I would call it

INIT_ARR(myNm,{1,2,3});

but preprocessors interprets any commas (also the one inside curly braces) as new macro parameter so it gives me error:

error:  #55-D: too many arguments in invocation of macro "INIT_ARR" 

preprocessor does not ignore () so I can do:

#define INIT_ARR(VAR_NAME,ARR_DATA) int VAR_NAME[] = {ARR_DATA}
INIT_ARR(myNm,(1,2,3));

but then it is interpreted as

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

which is not correct for C.

Is there a way how to do it?? For example remove braces from parameter?

2 Answers
Related