Features of the mql5 language, subtleties and tricks - page 307
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
Another (indirect) second-level macro is required to separate, combine and structure the parameters of nested macros.You propose to create a different version of the string translation macro for each case. But then the solution is not universal, because it depends on the type of macro.
It turns out that there is no general mechanism of macro to string translation.
You propose to create a different version of the string translation macro for each case. But then the solution is not universal, because it depends on the type of macro.
It turns out that there is no general mechanism of macro to string translation.
Watch for for nested macro calls. Parameters to macros which themselves are macros get expanded on 2 stages;
if arg is a macro, then it will be totally expanded (i.e., evaluated, or textual replacement happens) at compiler/parser time.
if arg is a macro (i.e., nested macro calls), then it will not be expanded (no textual replacement inside macro body) on the first pass.
Also in the first pass # stringify operator and ## concat operator get ON HOLD. So, that you need an 2nd level indirection macro.
In the second pass, the macro body is re-evaluated again for further expansions (textual replacement, stringify and concat).
It is a limitation of macros, because they are evaluated by the compiler at runtime as text (not as executing code).
This is a limitation of macros, as they are evaluated by the compiler at runtime as text (rather than executable code).
Solution.
If we're talking about parametric macros, here's an interesting question: how to expand a comment in a macro. In such a macro
the comment is needed to replace the text in input in the terminal. However, the macro does not expand the comment, but omits it.
How to expand a comment in a macro.
No way.
I do. Thank you.
Solution.
I don't believe that using pure macros is the solution. Using a helper function like StringSubst() or Print() that evaluates at runtime can help avoid the standard macro parameter disclosure order (2 steps). This is the semantics of how the C compiler works.
I don't consider it a solution using pure macros. Using a helper function like StringSubst() or Print() that is evaluated at runtime can help to escape the default order of macro parameter expansion (2 steps). These are the semantics of how the C compiler works.
Pure macros ?
Macros in MQL doesn't have all the features of C++. And even C++ macros are very limited, compared to some existing solutions (like M4 for example).
What I will never understand is why a company choose to create a proprietary language (MQL) to finally decide to use an archaic macros system beside it. All of these features should be better implemented directly in the language.
Anyway, we have to deal with it.