CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    23

    I want to acheive this

    I want to acheive the following
    void ab()
    {
    }

    #define X1 a
    #define X2 b
    #define X X1##X2
    X(); // So I want this to be equivalent to calling ab()


    any ideas how i can acheive that ?

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449
    Why not just call ab()?

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Sep 2000
    Location
    Russia
    Posts
    262
    // Helper macro _CONCAT:
    // The following piece of macro magic joins the two
    // arguments together, even when one of the arguments is
    // itself a macro (see 16.3.1 in C++ standard). The key
    // is that macro expansion of macro arguments does not
    // occur in _CONCAT2 but does in _CONCAT1.

    #define _CONCAT( _HEAD, _TAIL ) _CONCAT1( _HEAD, _TAIL )
    #define _CONCAT1( _HEAD, _TAIL ) _CONCAT2( _HEAD, _TAIL )
    #define _CONCAT2( _HEAD, _TAIL ) _HEAD##_TAIL

    Now if you use the macro _CONCAT like this:

    #define X1 a
    #define X2 b
    _CONCAT( X1, X2 )

    you will get 'ab' after prefrocessing.

    BTW: You can add /P option in Project Settings\C/C++\General\Project Options to get preprocessed output in MSVC Dev Studio.

  4. #4
    Join Date
    Apr 1999
    Posts
    23
    you are the man

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured