Download MetaTrader 5

Is there a possibility to control multiple ( nested #include ) inclusions of .MQH header file in MQL4?

To add comments, please log in or register
jackee1234
197
jackee1234  

For MQL4, will it include the .mqh header files multiple times (or does it matter?), if say one header file makes use of the header files we already included?

If yes, how to prevent that?

fxsaber
10891
fxsaber  

Do not worry about it. Everything will be compiled without problems.


PS See also #define and #ifdef.

Stanislav Korotky
23361
Stanislav Korotky  
jackee1234:

For MQL4, will it include the .mqh header files multiple times (or does it matter?), if say one header file makes use of the header files we already included?

If yes, how to prevent that?

Use #ifdef quard. Best programming practices suggest to wrap every header file source code into a construction like this

#ifndef _HEADER_ID_
#define _HEADER_ID_

... actual source goes here

#endif
jackee1234
197
jackee1234  
Stanislav Korotky:

Use #ifdef quard. Best programming practices suggest to wrap every header file source code into a construction like this


Do we need to take care of this or just let mql4 take care of it (since it does not throw errors with multiple includes)?

whroeder1
17093
whroeder1  
jackee1234: Do we need to take care of this or just let mql4 take care of it (since it does not throw errors with multiple includes)?
Unlike most other languages, MT4/5 guards itself.
  1. Guards are unnecessary.
  2. But prevents you from doing preprocessor tricks like:
    double A,B
    #define Trick A
    #include "Trick.mqh" // does something with A
    #undef Trick
    #define Trick B
    #include "Trick.mqh" // does something with B
    #undef Trick


To add comments, please log in or register