How to use # inside a macro definition

"Gergely, Tamás" gertom@inf.u-szeged.hu
Mon Nov 10 10:21:00 GMT 2003


Hello!

I don't know if there is an escape char or not. But if you write:

#ifdef EVAL
#define exmp(par1,par2) { par1 = par2; }
#else
#define exmp(par1,par2) { }
#endif

it will work. As I know, your example practically equals:

#define exmp(par1,par2) { #ifdef EVAL 	par1 = par2; #endif	}

so "#ifdef" and "#endif" are not in the beginning of the lines (where they 
have to be).

gertom

Kapileswar Rao wrote:
> Hello ,
>    I need some help regarding how to use # inside macro definition in C
> macros. I get an error, '#' is not followed by a macro parameter. I
> understand the reason but is there no escape character to avoid it
> expecting a macro parameter.
> 
> An example of my macro definition is
> 
> #define exmp(par1,par2) {\
> #ifdef EVAL   \
> 	par1 = par2; \
> #endif  \
> 	} 
> 
> Anticipating Help.
> thanks and regards,
> --Kapil


-- 
**************************************************************************
* Gergely TamĂĄs                            e-mail:gertom@inf.u-szeged.hu *
* ICQ:104783919                       http://www.inf.u-szeged.hu/~gertom *
**************************************************************************



More information about the Gcc-help mailing list