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

 

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?

 

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


PS See also #define and #ifdef.

 
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
 
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)?

 
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


Reason: