Jump to content
  • Advertisement
Sign in to follow this  
Icebone1000

Macro to substitute the #ifdef DEBUG #endif pair

This topic is 2535 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way to create a macro to accept anything as parameter, to avoid a bunch of ugly #ifdef DEBUG #endif?
I tried:


#ifdef _DEBUG
#define DBG(param) param
#else
#define DBG(param)
#endif



But I cant use it, i.e., to initialize a debug only member in a initialization list:



myClass::myClass():var1(0) DBG(, var2(param) )
{..}


because of the comma, "param" is ignored..

Can I create a macro that just copy and paste everything?

Share this post


Link to post
Share on other sites
Advertisement
I think you will have to surround the content you pass to the macro inside parenthesis.
DBG((, var2(param) ))

Share this post


Link to post
Share on other sites

I think you will have to surround the content you pass to the macro inside parenthesis.
DBG((, var2(param) ))


This doesnt work, cause the parenthesis goes to the initialization list, its not discarded..


Share this post


Link to post
Share on other sites
First declare a macro for the comma and use that instead of the comma
#define COMMA ,
... DBG(COMMA var2(param) ) ...

I know, it is not very nice. I guess it's just easier to use #ifdef and #endif.

Share this post


Link to post
Share on other sites

First declare a macro for the comma and use that instead of the comma
#define COMMA ,
... DBG(COMMA var2(param) ) ...

I know, it is not very nice. I guess it's just easier to use #ifdef and #endif.


That works on VC, also works on GCC for simple situation.
For complex macro, it can't compile.

Use this,

#define COMMA() ,
... DBG(COMMA() var2(param) ) ...

will work well.

However, on GCC, if COMMA() is passed to macro A, then A pass it to another macro, it will fail compile too.
So always using COMMA() as first level parameter.
VC doesn't have that limitation.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!