Any elegant way to do this?

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
 
M

Mark A. Odell

(e-mail address removed) (P L) wrote in

I have codes with blocks like this:
[snip]

We saw your first post, please wait for a reply instead of posting the
same thing over and over. It can take days for someone to give you an
answer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top