Is there a way to ignore macros?

Started by
7 comments, last by Jiia 21 years, 5 months ago
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
Advertisement
tried the latter version?
Uh, nope, but I just did. I assume it won''t work since #ignore didn''t turn blue (keyword color). Too Bad
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

zephyr

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]
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]
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

zephyr

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
daerid@gmail.com
Thanks for the help, I''ve been meaning to figure this out forever. Very much appreciated.

This topic is closed to new replies.

Advertisement