Archived

This topic is now archived and is closed to further replies.

Jiia

Is there a way to ignore macros?

Recommended Posts

The only reason I ask is because I spotted a define in one of the DirectX includes, something like this.. #define SOMETHING(xx) 0L In my engine, I use a "#define DB(text) DebugOut(text)" that opens and writes to a debug log text file. I also have a define within the compiler options, "FINAL_RELEASE". When it is defined, all debugging methods should be ignored. I could do this for every line that uses DB().. #ifndef FINAL_RELEASE DB("Starting up"); #endif Or I could wrap everything in the DebugOut function inside the ifndef above, so it would call an empty function in final release. Or I could do something like this.. #ifdef FINAL_RELEASE #ignore DB(text) #else #define DB(text) DebugOut(text) #endif Is there a possible way to do this? So the compiler will ignore all instances of "DB(something);" ? Thanks, Jiia

Share this post


Link to post
Share on other sites
I''ve got something like this in one of my MSVC projects (modified for your purposes):

#ifdef FINAL_RELEASE
#define DB(text) /***/
#else
#define DB(text) DebugOut(text)
#endif

This just turns your macro call into a comment. I have a feeling that any standard C/C++ compiler should cope with that syntax (could be wrong, though).


zephyr

Share this post


Link to post
Share on other sites
sorry, i missed the ignore part. here's what you need:

#ifdef FINAL_RELEASE
#define DB(text)
#else
#define DB(text) DebugOut(text)
#endif


[edited by - niyaw on October 31, 2002 10:42:37 PM]

Share this post


Link to post
Share on other sites
I think both of those will do the about the same thing, but what about the floating ";"'s. Will those hurt anything? And in a situation like this, what would happen..?:

if(EngineSetup)
DB("Success");
else
DB("Fail");

=

if(EngineSetup)
/***/;
else
/***/;

or

if(EngineSetup)
;
else
;

They compile OK, but are they REALLY OK?

Thanks again,
Jiia

[edited by - Jiia on October 31, 2002 10:55:19 PM]

Share this post


Link to post
Share on other sites
I don''t see any reason why the semi-colons would cause trouble. They''re just statement terminators, and it so happens that there''s just no statement to terminate now... It effectively turns them into "do nothing" statements. If the compiler''s intelligent enough, it will be able to optimise the whole "if" construct out of the executable, since it now does nothing.

zephyr

Share this post


Link to post
Share on other sites
quote:
Original post by niyaw
sorry, i missed the ignore part. here''s what you need:

#ifdef FINAL_RELEASE
#define DB(text)
#else
#define DB(text) DebugOut(text)
#endif




Listen to him, he''s right

Share this post


Link to post
Share on other sites