Errors, bugs, questions - page 710

 

Needed to determine the size of a variable array, but the error comes out:

void OnStart()
  {
   int j=1000;
//---
   double arrBalancesTS[][j];
  }

//---

//---

It works directly with constants (#define) and with a numeric value, but not like this. Why?

 
tol64:

Needed to determine the size of a variable array, but the error comes out:

//---

//---

It works directly with constants (#define) and with a numeric value, but not like this. Why?

With constants, it is a static array, and with a variable, it is dynamic. And the size of a dynamic one is determined by ArrayResize
Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
  • www.mql5.com
Основы языка / Типы данных / Объект динамического массива - Документация по MQL5
 

tol64:

Why?

The second and subsequent dimensions have a fixed size. It can only be set by a constant.
 
tol64:

With constants (#define) and with a numeric value, it works directly, but not like this. Why?

Because when defining with #define, the compiler simply replaces the macro encountered with the correct entry before compilation. Therefore it sees

void OnStart()
  {
//---
   double arrBalancesTS[][1000];
  }

that does not contradict the MQL5 language.

 
Yedelkin:

OK. Then I'll take the nerve. So, the description of the Print() function says that "data of the double type are printed with the precision of 16 decimal digits after the point". In fact, it turns out that the Print() function outputs somewhat rounded data:

ND 0 victorg2 (EURUSD,M1) 11:04:42 Print(b)=200.0
MP 0 victorg2 (EURUSD,M1) 11:04:42 Print(DoubleToString(b,16))=199.999999999999999716

The point is that a real number is stored in memory with no more than 17 significant digits.

Try this example to feel the difference:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   double a,b;

   a=7.0/200.0;
   b=7.0/a;
   Print("Print(b)=",b);
   Print("Print(DoubleToString(b,16))=",DoubleToString(b,16));

   Print("Print(StringFormat(b,%.15G))=",StringFormat("%.15G",b));
   Print("Print(StringFormat(b,%.16G))=",StringFormat("%.16G",b));
   Print("Print(StringFormat(b,%.17G))=",StringFormat("%.17G",b));
   Print("Print(StringFormat(b,%.18G))=",StringFormat("%.18G",b));
   
//19999999999999997
   Print("Print(StringFormat(b,%.15f))=",StringFormat("%.15f",b));
   Print("Print(StringFormat(b,%.16f))=",StringFormat("%.16f",b));
   Print("Print(StringFormat(b,%.17f))=",StringFormat("%.17f",b));
   
  }
//+------------------------------------------------------------------+
The description in the help will be corrected.
 
notused:
With constants, it is a static array, and with a variable, it is dynamic. And the size of a dynamic one is determined using ArrayResize.
TheXpert:
The second and subsequent dimensions have a fixed size. It can only be set by a constant.
Rosh:

Because when defined with #define, the compiler simply replaces the macro encountered with the correct entry before compilation. Therefore it sees

that does not contradict the MQL5 language.

Thank you. Can you tell me, what can be done, if the size of an array in the first and second dimension is defined in calculations and can't be a constant? With ArrayResize(), you can resize only the first dimension, after all. And why can I resize an array by applying a variable value, while it cannot be set initially?
 
tol64:
Thank you. Can you tell me what can be done if the size of an array in both the first and second dimension is determined by calculations and cannot be a constant? With ArrayResize(), you can only change the size of the first dimension. And why can you resize an array using a variable, while it cannot be set initially?
please use classes.
 
tol64:
Thank you. Can you tell me what can be done if the size of an array in both the first and second dimension is determined by calculations and cannot be a constant? With ArrayResize(), you can only change the size of the first dimension. And why can I resize an array by applying a variable value, while it cannot be set initially?
Take a look at the overloading operations section for an example for the CMatrix class, maybe this will work for you.
 
Hello.

I can't find how to make 2 classes exchange messages.

I want the A class to have a link to B and the B class to A.
I got a compilation error, maybe MQL5 doesn't allow that. But without it the object programming is used at 30%.

The solution could be to write one big GOD Class that knows and knows everything. But this doesn't seem very elegant to me.
Who may help with the solution?

Thanks in advance!
Reason: