Hi,
I have many Print debug messages in some of my codes I'd like to have them removed when compiling a "relase version". In order to avoid comment many lines, the normal strategy I have in mind is to use preprocessor directives as follows:
The problem with the above line of code is that it has 3 lines, making the code a little "dirty", and I'd like to keep it clean by diminishing it to only one line. Using that with and if clause would be simple:
The problem with that above solution, AFAIK, is that the "if (false)" before every debug message will consume some processing time and I'd like to avoid that unnecessary CPU consumption. A solution like the first one, where the entire print debug code is removed from the compiled code, is preferable. But how to do it? I thought about putting the entire #ifdef inside a define like as follows:
Now when I compile the code with only the define parts, it compiles fine. If I go to the code and, with a single line, write "
, it runs fine. But the moment I try to call the debug message, it gives me errors:
So, is there a way to implement what I want? Or if my desire is to keep the debug messages in just one line, I'l have to use the if(true) / if(false) way?
Hello , you can do :
#define DEBUG_MSG true void DebugPrint(string message){ if(DEBUG_MSG){ Print(message); }}
then replace all Print( with DebugPrint(
That is if you don't mind accessing the DebugPrint function
If you do mind use this :
#define USE_DEBUG_MSG #ifdef USE_DEBUG_MSG #define DEBUG_MSG(_M) _M #else #define DEBUG_MSG(_M) #endif //in code //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create timer EventSetTimer(60); Print("Bread Above"); DEBUG_MSG(Print("Hamburger");) Print("Bread Below"); //--- return(INIT_SUCCEEDED); }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I have many Print debug messages in some of my codes I'd like to have them removed when compiling a "relase version". In order to avoid comment many lines, the normal strategy I have in mind is to use preprocessor directives as follows:
The problem with the above line of code is that it has 3 lines, making the code a little "dirty", and I'd like to keep it clean by diminishing it to only one line. Using that with and if clause would be simple:
The problem with that above solution, AFAIK, is that the "if (false)" before every debug message will consume some processing time and I'd like to avoid that unnecessary CPU consumption. A solution like the first one, where the entire print debug code is removed from the compiled code, is preferable. But how to do it? I thought about putting the entire #ifdef inside a define like as follows:
Now when I compile the code with only the define parts, it compiles fine. If I go to the code and, with a single line, write "
, it runs fine. But the moment I try to call the debug message, it gives me errors:
So, is there a way to implement what I want? Or if my desire is to keep the debug messages in just one line, I'l have to use the if(true) / if(false) way?