Friday, 15 May 2015

c - Macro with variable length of parameters -



c - Macro with variable length of parameters -

is there way #define macro variable length of parameters?

#define call(ar1, ar2, ar3) #endif

in c code

call(0); call(0,1); call(0,1,2)

all invoke above phone call macro. if ar2, ar3 not used, preprocessor ignore line ar2 or ar3.

yes, take @ one: http://gcc.gnu.org/onlinedocs/cpp/variadic-macros.html

key word __va_args__ ( variadic macros ):

a macro can declared take variable number of arguments much function can. syntax defining macro similar of function. here example:

#define eprintf(...) fprintf (stderr, __va_args__)

c gcc

No comments:

Post a Comment