Any elegant way to do this?

Discussion in 'C Programming' started by P L, Oct 17, 2003.

  1. P L

    P L Guest

    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
    P L, Oct 17, 2003
    #1
    1. Advertising

  2. (P L) wrote in
    news::

    > 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 ->
    --
    Mark A. Odell, Oct 17, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Braky Wacky
    Replies:
    8
    Views:
    694
    spalding
    Jul 15, 2004
  2. Morten Wennevik

    Any elegant way of doing this?

    Morten Wennevik, Nov 8, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    393
    Morten Wennevik
    Nov 8, 2005
  3. Licheng Fang
    Replies:
    5
    Views:
    428
    =?ISO-8859-15?Q?Juli=E1n?= Albo
    Sep 23, 2006
  4. Paul Miller
    Replies:
    6
    Views:
    346
    Malte Helmert
    Nov 24, 2009
  5. Patrick Li
    Replies:
    4
    Views:
    123
    Patrick Li
    Aug 10, 2008
Loading...

Share This Page