Why can't we redefine #define? (please to MQL5 programmers)

 

Hello.

Why can't we redefine #define preprocessor directive?

For example, very usefull...

#define InputTab MyTab_0
#include "MyFunctionA.inc"
#define InputTab MyTab_1
#include "MyFunctionA.inc"
#define InputTab MyTab_2
#inlude "MyFunctionA.inc"

Well.  The same function.  Just redefine names of input tables.

It can't be done.


Today is an naightmare, for example:

the copy of the same funcion, different by name, internal names, sorry...

OnInit()
{
   // Read tables of bar and color from files.
   #define TabOutWPDT_Nr00 MojaPrzesTabVSZ
   #define FileWPDT_Nr00 Symbol()+"_MojaPrzesTabVSZ.bin"
   #include "ReadFileToTab_Nr00.inc"
   #define TabOutWPDT_Nr01 MojaPrzesTabCOL
   #define FileWPDT_Nr01 Symbol()+"_MojaPrzesTabCOL.bin"
   #include "ReadFileToTab_Nr01.inc"
}

#include "ReadFileToTab_Nr00_Dane.inc"
#include "ReadFileToTab_Nr01_Dane.inc"
#include "WriteTabToFile_Nr00_Dane.inc"
#include "WriteTabToFile_Nr01_Dane.inc"
#include "WriteTabToFile_Nr02_Dane.inc"
#include "WriteTabToFile_Nr03_Dane.inc"

OnDeinit()
{
   // Write tables of bars and color to files.
   #define TabInpZTDP_Nr02 MojaPrzesTabVSZ
   #define FileZTDP_Nr02 Symbol()+"_MojaPrzesTabVSZ.bin"
   #include "WriteTabToFile_Nr02.inc"
   #define TabInpZTDP_Nr03 MojaPrzesTabCOL
   #define FileZTDP_Nr03 Symbol()+"_MojaPrzesTabCOL.bin"  
   #include "WriteTabToFile_Nr03.inc"
}

Please do not type "Read documetatnion"

The same function #include "FunctionName.inc"

and redefiniction of input/output static tables by changing #define


Thanks a lot.

Paolo_ecn

 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button



 

I dont understand, but you cannot include the same file multiple times. The compiler will remove all subsequent includes and only consider the first mentioning.

Redifinition of an already existing defined constant can be done like this:

#define MY_BASE_STR "test-str"

printf("%s", MY_BASE_STR);

#ifdef MY_BASE_STR
        #undef MY_BASE_STR
        #define MY_BASE_STR "subsequent definition"

#endif

printf("%s", MY_BASE_STR);


include files usually have the ".mqh" extension, not ".inc".

 
Paolo_ecn:

You have been told to edit your first post

You have added additional posts without using the code button. I have deleted them. Please post code properly.

Sergey Golubev #:

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button


 

To Mr Dominik Christian Egert, top secret.

<Deleted>

Solved:

// TestDefine

void OnStart()
{
   #define String_PM "A"
   #include "PrintMacro00.mq5"
         
   #ifdef String_PM
      #undef String_PM
   #endif 
   
   #define String_PM "B"
   #include "PrintMacro01.mq5"
   
   PlaySound("expert.wav");
}

/*

File "PrintMacro00.mq5":
   Print(String_PM);

File "PrintMacro01.mq5"
   Print(String_PM);

Tne same file, without changes.  Only change name for 00, 01...
and use many times.  The same "function" - macro, input/output
parameters are redefined.  For example:


   // Calculate bar color based on Data Aquisition
   #define TabWeKVSZ_VSZ MojaTabVSZ
   #define TabWeKVSZ_DaqMin MojaTabDaqMin
   #define TabWeKVSZ_DaqTim MojaTabDaqTim
   #define TabWeKVSZ_DaqAsk MojaTabDaqAsk
   #define TabWeKVSZ_DaqBid MojaTabDaqBid
   #define TabWyKVSZ_Kol MojaTabCOL
   #include "Koloruj_VSZ.inc"

Thanks a lot.

*/

PlaySound("expert.wav");