Macro thing...

Started by
13 comments, last by Javelin 20 years, 8 months ago
ok...

Guess I have to solve it some other way then.. :
Thank you all for you help...

--- edit ---
quote:
Of course, you could do it with all sorts of operator overloads. Should you? It depends upon the situation .


gahhh... Don't want to even think about it... it would become hundreds of functions... :D
I can see the benefit of it in a situation that differ from mine though...


// Javelin
-- Why do something today when you can do it tomorrow... --

[edited by - Javelin on August 19, 2003 7:29:07 AM]
// Javelin// Assumption is the mother of all fuckups...
Advertisement
quote:Original post by Beer Hunter
In C++, I''m not aware of any standard way. However, there''s another way to get the same effect for this example: #define PRINTF printf


Javelin: Did you even try this?
#ifdef _NODEBUG_  #define DEBUGTXT //#else  #define DEBUGTXT debug.Write#endif 


That should do the trick. However, try it, don''t trust it as the relationship between comments and the preprocessor varies between compilers.

Another way would be to make debug.write inline, and #ifdef the contents of the function. Hey presto! no code generated.
#ifdef _NODEBUG_
#define DEBUGTXT if (true) ; else debug.Write
#else
#define DEBUGTXT if (false) ; else debug.Write
#endif

Any halfway decent compiler should optimize out code in an else block that never executes. You could do something similar though, if you have your Debug class, or whatever, overload operator (). IE:

class Debug{//...classtemplate <class U>Debug& operator ()(const U& msg){    // output msg    return *this;}};#define DEBUGTXT if (false) ; else debug//Then use it like so:DEBUGTXT("An error has occured: Value = ")(myVariable)


desertfox
"Is life so dear, or peace so sweet, as to be purchased at the price of chains and slavery?" - Patrick Henry
quote:
Javelin: Did you even try this?


Damn... nope... missed (or forgot) it... :\
But yes... it should work for my pupose. I don''t like the comment thing though (as in dagarach example), but I don''t think it could cause too much trouble.

The way Desert Fox points out should work as well.

Thanks againg for your time. :D

// Javelin
-- Why do something today when you can do it tomorrow... --
// Javelin// Assumption is the mother of all fuckups...

This topic is closed to new replies.

Advertisement