I am writing a macro like this

#define MACRO(a,b) #ifdef _DEBUG a+b #endif
But on compiling I get 2 errors : "Expected macro formal parameters
It seems to me that compiler is interpreting #ifdef and #endif as macro parameters
Any workaround for this problem? Or can we put precompilers inside a c++ macro

TI
Sunil

Re: Can I put #ifdef inside a macro with parameters? by Roger

Roger
Fri Apr 23 06:33:15 CDT 2004

No.. instead use

#ifdef _DEBUG
#define MACRO(a,b) a+b
#endif



Re: Can I put #ifdef inside a macro with parameters? by Guido

Guido
Fri Apr 23 06:34:24 CDT 2004

> #define MACRO(a,b) #ifdef _DEBUG a+b #endif

No, you can't. The block inside #ifdef and #endif must be in new lines. Why
don't you do this:

#ifdef _DEBUG
#define MACRO(a,b) a+b
#else
#define MACRO(a,b)
#endif

In release your MACRO will do nothing, but the compiler knows it.

Guido



Re: Can I put #ifdef inside a macro with parameters? by anonymous

anonymous
Fri Apr 23 07:11:05 CDT 2004

Hi Guid
Thanks.... This is exactly what I was looking for. :)