#define a line comment symbol (//) - possible?

To add comments, please log in or register
terminalstat
46
terminalstat  

I was just curious: for debugging purposes I want some of Print() functions to be commented at once. Here's my approach that does not work:


#define DEBUG // -debug switcher, comment line for production

//debug printer:
#ifdef DEBUG
   #define DB //
#else
   #define DB 
#endif 

DB Print("some debug info.."); 

//want to replace DB -> "//" in case DEBUG is defined, so compiler see:

// Print("some debug info.."); 

Is it possible with MQL5?


PS: I've read https://www.mql5.com/en/articles/654 but want exactly above approach.


Thank's

Debugging MQL5 Programs
Debugging MQL5 Programs
  • www.mql5.com
This article is intended primarily for the programmers who have already learned the language but have not fully mastered the program development yet. It highlights the key issues that every developer deals with when debugging a program. So, what is debugging? Debugging is a stage in program development meant for detecting and removing program...
Alain Verleyen
38009
Alain Verleyen  
terminalstat:

I was just curious: for debugging purposes I want some of Print() functions to be commented at once. Here's my approach that does not work:


Is it possible with MQL5?


PS: I've read https://www.mql5.com/en/articles/654 but want exactly above approach.


Thank's

Of course not.

#define DEBUG // -debug switcher, comment line for production

#ifdef DEBUG Print("some debug info.."); #endif 
William Roeder
19968
William Roeder  
  1. Comments are stripped before processing the tokens (#define) so no.

  2. #ifdef DEBUG
       #define DB // This will not work, same in either case.
    #else
       #define DB 
    #endif 
    #ifdef DEBUG
       #define DB true
    #else
       #define DB false
    #endif 
    if(DB) Print("some debug info.."); else

lippmaje
845
lippmaje  

You can use a #define to switch logging on altogether like so:

#define DEBUG // comment out with '//' when done

#ifdef DEBUG
  #define DebugPrint(s) Print(s)
#else
  #define DebugPrint(s)
#endif

void OnTick() {
   ...
   DebugPrint("debug idx="+(string)idx);
}

It will become even more advanced if you introduce a log level.

To add comments, please log in or register