At least this works:
//+------------------------------------------------------------------+ //| test_PreProc.mq5 | //| Calli | //| https://www.mql5.com/de/users/gooly | //+------------------------------------------------------------------+ #property copyright "Calli" #property link "https://www.mql5.com/de/users/gooly" #property version "1.00" //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ #define _arWsz(A) __FUNCTION__+"["+(string)__LINE__+"] "+ #A+"[] sz: " + (string(ArraySize(A))) // print array with array name template<typename T> void ArrayPrt(T &arr[], const string inf) { Print(inf); ArrayPrint(arr); } void OnStart() { //--- int a[]={-5,-4,-3,-2,-1,0,1,2,3,4,5}; double b[]={1,5,2.4,3.3}; ArrayPrt(a,_arWsz(a)); ArrayPrt(b,_arWsz(b)); } //+------------------------------------------------------------------+
=>
2023.07.14 09:33:18.353 test_PreProc (EURUSD,H1) OnStart[27] a[] sz: 11
2023.07.14 09:33:18.353 test_PreProc (EURUSD,H1) -5 -4 -3 -2 -1 0 1 2 3 4 5
2023.07.14 09:33:18.353 test_PreProc (EURUSD,H1) OnStart[28] b[] sz: 4
2023.07.14 09:33:18.353 test_PreProc (EURUSD,H1) 1.00000 5.00000 2.40000 3.30000
Carl Schreiber:
This does not compile:
But this does and it works as intended:
Why?
Here the script to test:
This prints:
This is due to macro expansion order. You must have macro extensions on the line of the macro definition, else expansion will not work, as there is no macro to expand in the first place.
Sometimes you need a macro that calls another macro just to get the expansion order correctly.
This is not only mql but all macro preprocessors limitations.
EDIT:
The "#" instruction only works on the macro definition line itself.
Oh, I see - stupid me.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
This does not compile:
'#arr' - invalid preprocessor command test_PreProc.mq5 19 15
But this does and it works as intended:
'test_PreProc.mq5' test_PreProc.mq5 1 1
code generated 1 1
0 errors, 0 warnings, 107 msec elapsed 1 1
Why?
Here the script to test:
This prints:
2023.07.14 09:22:19.189 test_PreProc (EURUSD,H1) -5 -4 -3 -2 -1 0 1 2 3 4 5
2023.07.14 09:22:19.189 test_PreProc (EURUSD,H1) 32 arr[] sz: 4
2023.07.14 09:22:19.189 test_PreProc (EURUSD,H1) 1.00000 5.00000 2.40000 3.30000