I have a function mainFunc
which needs to call a several times another function process
. A process
has a lot of arguments but mainfunc
in different calls change only two of them/ Instead of another it passes local variables which are defined and assigned before this calls to process
. So I wrote a simple macro which substitutes local variables in calls to process
:
#define DO_PROCESS(pred1, est1) \
do \
{ \
process(pred1, est1, arg1, arg2, arg3); \
++id; \
delete est1; \
} while(0)
arg1
, arg2
, arg3
are local variables in mainFunc
, so I hope my macro will just use them. In mainFunc:
int arg1, arg2, arg3;
arg1 = AssignFirst();
...
Pred* pred;
Est* est;
int estArg;
int predArg;
pred = new Pred(predArg);
DO_PROCESS(pred, new Est(estArg));
delete pred;
pred = new Pred(predArg2);
DO_PROCESS(pred, new Est(estArg2));
delete pred;
pred = new Pred(predArg3);
DO_PROCESS(pred, new Est(estArg3));
delete pred;
....
However I get C2059 and C2143 errors pointing to closing curly brace and semicolon around it respectively in last line of macro.
What's wrong with it??