CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2001
    Location
    Dallas, Tx, USA (originally fromIndia)
    Posts
    154

    encode the #define...

    Hi All,
    i am having a problem understanding the below piece of code:
    #define DECLARE_OLD_HANDLE(a) \
    typedef struct a##__ { int unused; } *a; \
    typedef a *P##a, *LP##a

    i want to know what are the __ and the ## used for.
    Regards,
    Preetham.

  2. #2
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557
    preetham,

    The double hash (##) is called the token-pasting operator. It is commonly used in macros to append strings at the preprocessor-level. The double-underscore (__) is part of a name which will be expanded in the macro. The backslashes (\) continue the macro definition over several lines.

    I guess that this complicated macro (let's say for the macro-parameter 'hdl') expands to something like:

    DECLARE_OLD_HANDLE(hdl)

    expands to

    typedef struct hdl__
    {
    int unused;
    }
    *hdl;
    typedef hdl *Phdl, *LPhdl

    Please double-check this using your preprocessor output, probably offered by your compiler using a compiler switch.

    Best regards.
    Chris.

    You're gonna go blind staring into that box all day.

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