Presenting the book "MQL5 Programming for Traders" - page 4

 

Reffering to https://www.mql5.com/en/book/basis/builtin_types/datetime

"For the maximum permitted value of date, a special constant, DATETIME_MAX, is provided in MQL5 ..."

The compiler shows me an error (picture attached) that there is no constant DATETIME_MAX in MQL5. Am I doing something wrong ?
Files:
 
R0bot #:

Reffering to https://www.mql5.com/en/book/basis/builtin_types/datetime

"For the maximum permitted value of date, a special constant, DATETIME_MAX, is provided in MQL5 ..."

The compiler shows me an error (picture attached) that there is no constant DATETIME_MAX in MQL5. Am I doing something wrong ?

At the time of writing, I've been told that this constant is about to be added to the list of built-in constants, but it looks like it's still not done.

 

I. Introduction:  


    1. Referring to https://www.learncpp.com/cpp-tutorial/constant-expressions-and-compile-time-optimization/
       

        1.1 "A constant expression ... contains only compile-time constants."  
       

        1.2 "A compile-time constant is a constant whose value must be known at compile time. This includes:  
               - Literals (e.g. 5)  
               - Const integral variables with a constant expression initializer (e.g. const int x { 5 };)
"

    2. Referring to https://www.mql5.com/en/book/basis/builtin_types/user_enums  
       

        "const int zero = 0; // runtime value is not known at compile time"
        "enum RISK
         {
           OFF  = zero, // error: constant expression required
"

        Based on point I.1, I can say that:


        2.1 0 is a literal, so it is a compile-time constant, therefore it is a constant expression that is known / evaluated at compile time.  
       

        2.2 The const integral variable (const int zero) has a constant expression initializer (0), therefore zero is a constant expression.

II. Question:


    What are the reasons (in MQL5) that the zero is not considered a constant expression (is not known at compile time) ?

 
R0bot #:
1.2 "A compile-time constant is a constant whose value must be known at compile time. This includes:  
               - Const integral variables with a constant expression initializer (e.g. const int x { 5 };)
"

This does not work in MQL. The MQL compiler does not replace constant variables with literal values ​​at compile time.

https://www.mql5.com/en/forum/463995#comment_54117505

 
R0bot #:

II. Question:


    What are the reasons (in MQL5) that the zero is not considered a constant expression (is not known at compile time) ?

Despite the fact that MQL5 is similar in many aspects to C++ and constantly adopting more features from C++, it still has differencies and incompatibilities, part of which are planned (such as constexpr), and part are NOT (for example, exceptions) to follow C++ closely. MQ pick MQL5 features for implementation according to their own schedule and priorities, which we are not aware of.

 

Reffering to https://www.mql5.com/en/book/basis/variables/initialization

1. "... set a breakpoint onto the string with the initialization of one of the global variables, such as m."
2. "... run the program for debugging, ... Debug -> Start on real data (F5)"
3. "... a new chart will open in the terminal, in which this script starts being executed ..., but it suspends immediately, and we get back to MetaEditor."

According to the steps of the attached picture:

a. Did I do something wrong ?

b. Is there something wrong with the breakpoint on the global variable ?

c. Do I have to set something else in MetaEditor ?

Also, I have noticed that it enters in debugging mode, only if I have a breakpoint on a local variable.

Files:
 
R0bot #:

Reffering to https://www.mql5.com/en/book/basis/variables/initialization

1. "... set a breakpoint onto the string with the initialization of one of the global variables, such as m."
2. "... run the program for debugging, ... Debug -> Start on real data (F5)"
3. "... a new chart will open in the terminal, in which this script starts being executed ..., but it suspends immediately, and we get back to MetaEditor."

According to the steps of the attached picture:

a. Did I do something wrong ?

b. Is there something wrong with the breakpoint on the global variable ?

c. Do I have to set something else in MetaEditor ?

Also, I have noticed that it enters in debugging mode, only if I have a breakpoint on a local variable.

It works for me as described, in the latest release 4410. Please, look into the terminal's logs for possible execution errors, check debugging settings. Make sure both the terminal and editor are running before you start debugging, because otherwise the connection between 2 programs may be lost (or not established properly).

 
Stanislav Korotky #:
It works for me as described, in the latest release 4410. Please, look into the terminal's logs for possible execution errors, check debugging settings. Make sure both the terminal and editor are running before you start debugging, because otherwise the connection between 2 programs may be lost (or not established properly).

According to the attached picture:

1. My latest release version is 4460. It's okay with this problem ?

2. In the terminal's logs:

    2.1 I don't have execution errors.

    2.2 Why, instead of stopping at the "Script loaded successfully" operation, actually continue automatically, in the same second, with "Script removed" and "MQL5 debugger disconnected" ?

3. I did not make any changes to the debugging settings.

4. Both the MetaTrader terminal and MetaEditor are running before I start debugging.

5. Weird behavior after pressing F5:

    I switch manually in MetaEditor and notice that the breakpoint from the global variable on line 12 (int m = 1;  // m = 1 place breakpoint on this line) has automatically moved to line 16 ({). Why ?

6.Still, I don't know what to do to solve the problem.

Files:
 
R0bot #:

According to the attached picture:

1. My latest release version is 4460. It's okay with this problem ?

...

5. Weird behavior after pressing F5:

    I switch manually in MetaEditor and notice that the breakpoint from the global variable on line 12 (int m = 1;  // m = 1 place breakpoint on this line) has automatically moved to line 16 ({). Why ?

Try under the latest release 4410. MQ could change compiler in the betas.

Try to uncheck first 3 checkboxes in the debug settings.

I don't know why break point is moved to another line without code - try to figure out how this happens, because this may be the reason of the issue - line 16 has no instructions to pause at.