Function Macro Does Not Work

Discussion in 'C++' started by Immortal Nephi, Sep 4, 2009.

  1. I wonder why main() is unable to invoke either fn_1 or fn_2 before it
    returns zero value to end the program. How can you fix function macro
    issue? I know that it does look like C style. How can I convert
    function macro to template?


    #define FN_NAME( name ) fn_##name
    #define FN( name ) void FN_NAME( name )()

    FN( fn_1 )
    {
    cout << "fn_1()" << endl;
    }

    FN( fn_2 )
    {
    cout << "fn_2()" << endl;
    }

    int main()
    {
    FN( fn_1 );
    FN( fn_2 );

    system("Pause");

    return 0;
    }
    Immortal Nephi, Sep 4, 2009
    #1
    1. Advertising

  2. "Immortal Nephi" <> wrote in message
    news:...
    > I wonder why main() is unable to invoke either fn_1 or fn_2 before it
    > returns zero value to end the program. How can you fix function macro
    > issue? I know that it does look like C style. How can I convert
    > function macro to template?

    [...]

    Try something like:
    _____________________________________________________________
    #include <iostream>


    #define FN_NAME( name ) fn_##name
    #define FN( name ) FN_NAME( name )()
    #define FN_PROTO( name ) void FN( name )


    FN_PROTO( fn_1 )
    {
    std::cout << "fn_1()" << std::endl;
    }

    FN_PROTO( fn_2 )
    {
    std::cout << "fn_2()" << std::endl;
    }


    int main()
    {
    FN( fn_1 );
    FN( fn_2 );

    return 0;
    }
    _____________________________________________________________
    Chris M. Thomasson, Sep 5, 2009
    #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. Dead RAM
    Replies:
    20
    Views:
    1,097
    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:
    568
    Jack Klein
    Sep 21, 2003
  3. Karim Thapa

    Why this MACRO does not work?

    Karim Thapa, Jan 20, 2004, in forum: C Programming
    Replies:
    7
    Views:
    382
    Keith Thompson
    Jan 21, 2004
  4. Patrick Kowalzick
    Replies:
    5
    Views:
    461
    Patrick Kowalzick
    Mar 14, 2006
  5. Nephi Immortal

    Macro does not work in source code.

    Nephi Immortal, Jul 29, 2011, in forum: C++
    Replies:
    20
    Views:
    807
    Ian Collins
    Aug 7, 2011
Loading...

Share This Page