Click to See Complete Forum and Search --> : encode the #define...


preetham
July 9th, 2002, 12:56 AM
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.

dude_1967
July 9th, 2002, 02:27 AM
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.

:)