Macro arguments with commas
Stuart Hood
stuart at siesoft.co.uk
Sat Apr 27 00:20:42 AEST 1991
I have a macro:
#define M(E) { static int v[] = E; \
int i; \
for (i=0; i<sizeof(v)/sizeof(int); i++) \
process(v[i]); }
so that I can go:
M({ 23 });
I would really love to go:
M({ 23, 27 });
but this produces "incorrect bracketing" errors from the compiler
because '{' doesn't escape the parameter in the same way that '('
does.
The only solution that I can think of is:
#define M(E) { int i=0; \
for (i=0; i<sizeof(E)/sizeof(int); i++) \
process(v[i]); }
...
static int val = { 23, 27 };
M(val);
Can anyone think of a neater solution? Please email; I'll post
the best solution (with due credits, of course).
Thanks in advance,
Stuart.
-
--
S I E M E N S Stuart Hood === Siemens Nixdorf House, Bracknell, Berks, UK
------------- Phone: + 44-344-850994 Email: stuart at siesoft.co.uk
N I X D O R F The trouble with everyone, is that they generalise too much
More information about the Comp.lang.c
mailing list