Préprocesseur

Le préprocesseur est un sous-système spécial du compilateur MQL5 qui sert à la préparation du code source du programme immédiatement avant que le programme ne soit compilé.

Le préprocesseur permet d'améliorer la lisibilité du code source. Le code peut être structuré en incluant des fichiers spécifiques contenant le code source de programmes mql5. La possibilité d'assigner des noms mnémoniques à des constantes spécifiques permet d'améliorer la lisibilité du code.

Le préprocesseur permet aussi de déterminer les paramètres spécifiques des programmes mql5 :

The preprocessor directives are used by the compiler to preprocess the source code before compiling it. The directive always begins with #, therefore the compiler prohibits using the symbol in names of variables, functions etc.

Each directive is described by a separate entry and is valid until the line break. You cannot use several directives in one entry. If the directive entry is too big, it can be broken into several lines using the '\' symbol. In this case, the next line is considered a continuation of the directive entry.

//+------------------------------------------------------------------+
//|  foreach pseudo-operator                                         |
//+------------------------------------------------------------------+
#define ForEach(index, array) for (int index = 0,                    \
   max_##index=ArraySize((array));                                   \
   index<max_##index; index++)    
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   string array[]={"12","23","34","45"};
//--- bypass the array using ForEach
   ForEach(i,array)
     {
      PrintFormat("%d: array[%d]=%s",i,i,array[i]);
     }
  }
//+------------------------------------------------------------------+
/* Output result  
   0: array[0]=12
   1: array[1]=23
   2: array[2]=34
   3: array[3]=45
*/

For the compiler, all these three #define directive lines look like a single long line. The example above also applies ## character which is a merge operator used in the #define macros to merge the two macro tokens into one. The tokens merge operator cannot be the first or last one in a macro definition.