P
P L
I have codes with blocks like this:
void h() {
..
..
..
a;
b1;
b2;
..
..
..
bn;
c;
..
..
..
}
and I need to change it to something like:
static void g()
{
b1;
b2;
..
..
..
bn;
}
void h() {
..
..
..
a;
#ifdef ABC
b1;
b2;
..
..
..
bn;
#else
f(g); /* f is some function taking g as arg */
#endif
c;
..
..
..
}
I don't like to copy the blocks because of two reasons: there are lot
of such changed need to be made; and any future changes in b1; ...; bn
will need changes in two places. I am reluctant to add a lot of
backslashes and put b1; ...; bn in a macro; and would prefer some
other elegant way. Also, I would prefer to keep the block of
statements themselves b1; ...; bn at their current places. I come up
with something like:
static void g();
void h() {
..
..
..
a;
#define BB \
b1; \
b2; \
.. \
.. \
.. \
bn;
#ifdef ABC
BB
#else
f(g);
#endif
c;
..
..
..
}
static void g() {BB}
#undef BB
But as I said earlier, I don't quite like the many extra backslashes.
Can someone shed some light? Thanks. - PL
void h() {
..
..
..
a;
b1;
b2;
..
..
..
bn;
c;
..
..
..
}
and I need to change it to something like:
static void g()
{
b1;
b2;
..
..
..
bn;
}
void h() {
..
..
..
a;
#ifdef ABC
b1;
b2;
..
..
..
bn;
#else
f(g); /* f is some function taking g as arg */
#endif
c;
..
..
..
}
I don't like to copy the blocks because of two reasons: there are lot
of such changed need to be made; and any future changes in b1; ...; bn
will need changes in two places. I am reluctant to add a lot of
backslashes and put b1; ...; bn in a macro; and would prefer some
other elegant way. Also, I would prefer to keep the block of
statements themselves b1; ...; bn at their current places. I come up
with something like:
static void g();
void h() {
..
..
..
a;
#define BB \
b1; \
b2; \
.. \
.. \
.. \
bn;
#ifdef ABC
BB
#else
f(g);
#endif
c;
..
..
..
}
static void g() {BB}
#undef BB
But as I said earlier, I don't quite like the many extra backslashes.
Can someone shed some light? Thanks. - PL