Conditional preprocessor directives

 

I like MT5 very much, especially on the debugger.  But right now it is slow and unstable, so in the meantime, I ported my MT4 codes over to MT5 and able to use the debugger.  For most parts I can use functions to encapsulate the differences but others (example the extern and input keywords for indicator parameters) I have to include 2 codes and comment out the MT5 codes when I compile in MT4 and vice versa.  This is becoming tedious.

I would like to ask for a conditional inclusion preprocessor directives (#ifdef, #ifndef, #if, #endif, #else and #elif) to help to maintain single code base for both MT4 and MT5.

Besides using it for the above purpose, it could be used to optimise simple functions without actually incurring an expensive function call during run time.   For example:

#define getmax(a,b) a>b?a:b 

 

It will not be realized in the near future

 

Hi William,

even if the official response is "don't hold your breath",
I'm entirely with you on this feature request!

Cheers

 
Ya it is ashame, this feature will be very helpful especially to those who sell their EA/indicators and want to maintain single source code across MT4 and 5.
 
williamwong:

 

I'd love to see it too.  It would be very easy to write a script in MQL5 which deletes debug code for a release version of an EA, like this.

#define DEBUG_CODE  

//#ifdef DEBUG_CODE  

// ... debug stuff in original EA to delete in the release version

//#endif 

 

As far as the #define functoin call goes, C++ has inlining for functions declared in the include file inside the class.  If MQL5 has this feature then it is better than #define because the compiler performs type-checking.  It would be great to have some documentation of optimiser behaviour such as this: does MQL5 support true inlining, ie overhead-free function calls, particularly for get/set functions?

Paul 

 
I am with you, too.
 
phampton:

 

I'd love to see it too.  It would be very easy to write a script in MQL5 which deletes debug code for a release version of an EA, like this.

#define DEBUG_CODE  

//#ifdef DEBUG_CODE  

// ... debug stuff in original EA to delete in the release version

//#endif 

 

As far as the #define functoin call goes, C++ has inlining for functions declared in the include file inside the class.  If MQL5 has this feature then it is better than #define because the compiler performs type-checking.  It would be great to have some documentation of optimiser behaviour such as this: does MQL5 support true inlining, ie overhead-free function calls, particularly for get/set functions?

Paul 

 


There is a macro "IS_DEBUG_MODE", below code shows how you can use it

if(IS_DEBUG_MODE)

  {
   // This code will be executed only in debug build.
   //  In the release build the optimizer will cut IF statement
 
}


Documentation will be as soon as the work on the optimizer will be finished

 
williamwong:

I like MT5 very much, especially on the debugger.  But right now it is slow and unstable, so in the meantime, I ported my MT4 codes over to MT5 and able to use the debugger.  For most parts I can use functions to encapsulate the differences but others (example the extern and input keywords for indicator parameters) I have to include 2 codes and comment out the MT5 codes when I compile in MT4 and vice versa.  This is becoming tedious.

I would like to ask for a conditional inclusion preprocessor directives (#ifdef, #ifndef, #if, #endif, #else and #elif) to help to maintain single code base for both MT4 and MT5.

Besides using it for the above purpose, it could be used to optimise simple functions without actually incurring an expensive function call during run time.   For example:

#define getmax(a,b) a>b?a:b 

It's not clear how to define and use it (I could not discovery it), but there is a news here about this topic:


72272
MetaQuotes 2013.11.02 08:18   PT

MetaTrader 5 Client Terminal build 871 

  1. MQL5: Fixed an issue that prevented testing of experts containing custom indicators in the form of a resource . Error affected including experts from MQL5 Market. 
  2. MQL5: Added support for conditional compilation # if [n] def, # else and # endif.

If someone has an complete example using the new resource of conditional compilation please publish the source code here.

Reason: