Download MetaTrader 5

Conditional preprocessor directives

To add comments, please log in or register
Do you need a programmer? Freelance service will find the developer you need!
williamwong
632
williamwong 2010.08.19 06:03 

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 

Alexey Da
Moderator
6606
Alexey Da 2010.08.19 16:55  

It will not be realized in the near future

Max Payne
411
Max Payne 2010.08.19 17:29  

Hi William,

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

Cheers

williamwong
632
williamwong 2010.08.20 09:52  
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.
Paul
784
Paul 2010.08.30 10:28  
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 

 

khryniewiecki
23
khryniewiecki 2010.09.03 20:19  
I am with you, too.
Ilyas
1206
Ilyas 2010.09.09 17:53  
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

Rogerio Figurelli
Moderator
39669
Rogerio Figurelli 2013.12.19 02:13  
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.

To add comments, please log in or register