Advertisement

Macro help needed(include #ifdef?)

Started by March 27, 2001 05:46 AM
3 comments, last by gimp 23 years, 10 months ago
The following macro doesn''t seem to work too well... Can anyone seen anything wrong with it? #define TRACE(data) \ #ifdef _DEBUG \ Trace(data); \ #endif //_Debug Thanks Chris
Chris Brodie
well it doesnt seem that your Trace function is doing anything. you have to go

#define Trace(data) (does what ever in here)
Advertisement
Basically all I want to do is a way of hiding all reference to the trace function in the release build (each trace writes to a logfile).

My idea was to use a macro to wrap the ifdef''s around the trace call so the preprocessor will remove all references to it in the release build.

Any ideas?

Thanks

Chris
Chris Brodie
Unfortunately, you can''t use put preprocessor commands inside a macro. Of course, this may be compiler specific, but any compiler that would be smart enough to allow this wouldn''t be following ANSI''s C Standard.

I believe I read an article stating that the next C standard would include a way to do what you want.

In the meantime, you can get around this by doing:

#ifdef _DEBUG

#define TRACE(data) \
Trace(data);

#elif _RELEASE

#define TRACE(data)

#endif


- Houdini
- Houdini
Bingo!

Thanks
Chris Brodie

This topic is closed to new replies.

Advertisement