Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Any elegant way to do this? (http://www.velocityreviews.com/forums/t315825-any-elegant-way-to-do-this.html)

P L 10-17-2003 05:58 PM

Any elegant way to do this?
 
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

Mark A. Odell 10-17-2003 06:04 PM

Re: Any elegant way to do this?
 
jsyzghan@yahoo.com (P L) wrote in
news:7f6f728b.0310170958.168c3ccc@posting.google.c om:

> 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.

--
- Mark ->
--


All times are GMT. The time now is 08:05 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.