I want o use the function alternate to a MACRO

Discussion in 'C Programming' started by parag_paul@hotmail.com, Dec 14, 2007.

  1. Guest


    > I have a
    > #define A(a,b,c,d)
    > sdafasdf/
    > sadfsadasd/
    > sadfsad/
    > sdf.


    > Now, I have another #define A_function(a,b,c,d) {
    > asdas;
    > asdas;
    > asd;}


    > Now at runtime, I want to use the function version of the MACRO .
    > I dont want to use the MACRO, since it is not debuggable
    > Please help
    , Dec 14, 2007
    #1
    1. Advertising

  2. pete Guest

    wrote:

    > > Now at runtime, I want to use the function version of the MACRO .
    > > I dont want to use the MACRO, since it is not debuggable
    > > Please help


    /* BEGIN new.c */

    #include <stdio.h>

    #define add_5(X) ((X) + 5)

    int (add_5)(int x)
    {
    return add_5(x);
    }

    int main(void)
    {
    int x = 6;

    /*
    ** This uses the macro directly.
    */
    printf("%d plus 5 equals %d\n", x, add_5(x++));



    /*
    ** This uses the function.
    */
    printf("%d plus 5 equals %d\n", x, (add_5)(x));
    return 0;
    }

    /* END new.c */


    --
    pete
    pete, Dec 14, 2007
    #2
    1. Advertising

  3. "" <> wrote:
    > > I have a
    > > #define A(a,b,c,d)


    I presume you meant to add a \ at the end.

    > > sdafasdf/
    > > sadfsadasd/
    > > sadfsad/
    > > sdf.


    See...

    http://c-faq.com/cpp/multistmt.html

    > > Now, I have another #define A_function(a,b,c,d) {


    Since this is another macro, but has a different name
    to the previous macro, I don't quite see what your real
    question is (though pete has answered what I think you
    want.)

    > > asdas;
    > > asdas;
    > > asd;}
    > > Now at runtime, I want to use the function version of
    > > the MACRO .


    Macro's stop existing even before compilation. So it's
    meaningless to say you do or don't want a macro to run
    at runtime.

    Please be careful with your terminology, both the macros
    you've supplied are function macros. So it's not obvious
    what you mean by "function version the MACRO."

    > > I dont want to use the MACRO, since it is not debuggable


    Perhaps you should look into inline functions, though they
    generally suffer similar problems. This is where log files
    are often superior to debuggers.

    --
    Peter
    Peter Nilsson, Dec 15, 2007
    #3
    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. Dead RAM
    Replies:
    20
    Views:
    1,091
    John Harrison
    Jul 14, 2004
  2. D Senthil Kumar

    macro name from macro?

    D Senthil Kumar, Sep 20, 2003, in forum: C Programming
    Replies:
    1
    Views:
    564
    Jack Klein
    Sep 21, 2003
  3. Patrick Kowalzick
    Replies:
    5
    Views:
    458
    Patrick Kowalzick
    Mar 14, 2006
  4. Chris
    Replies:
    2
    Views:
    669
    Chris
    Mar 4, 2007
  5. Replies:
    10
    Views:
    325
    Sean O'Halpin
    Jul 17, 2006
Loading...

Share This Page