Questions from a "dummy" - page 123

 
papaklass:

MqlRates mrate[];//массив нулевого размера

Use ArrayResize and ArrayInitialize.

Usually with CopyRates this structure is used.

 
papaklass:

Renat said it was better to do it like this:

MqlRates mrate[] = {0};    //структура для хранения информации о ценах, объемах и спреде.

Let's try to figure it out. As far as I remember, Renat was talking about initializing a simple variable, not an array. With battles similar examples appeared in the Handbook:

//--- инициализация всех полей структуры нулевым значением
MqlTradeRequest request={0};

You, on the other hand, are trying to initialise an array, not a simple variable, when declaring it. I found this example in the Handbook:

double f[]     = { 0.0, 0.236, 0.382, 0.5, 0.618, 1.0 };

Если размер инициализируемого массива не указан, то он 
определяется компилятором, исходя из размера инициализирующей последовательности.

The array here is initialized with a finite number of values, and the explanation says that the compiler determines the size of such an array relying on the number of these values. I am too lazy to check it - the size of array f[] from the example is most likely to be 6.

In your sample, the size of the {0} initializing sequence is 1. Consequently, the compiler will most likely define the size of array mrate[] as 1. Here, for the sake of interest, specify it this way:

MqlRates mrate[] = {0,0,0,0,0,0,0,0,0,0,0,0};    //структура для хранения информации о ценах, объемах и спреде.
Will it cause an error?
 
papaklass:
I was confused. Swan explained it clearly. I took the wrong structure. It doesn't need to be initialized at all because it takes values. You need to initialize the ones that give their values. I was wrong.

Well, that's the main thing. The question about Renate was interesting in itself, so I figured something out, too.

 

double f[] = { 0.0, 0.236, 0.382, 0.5, 0.618, 1.0 }; not a dynamic array.

Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
  • www.mql5.com
Основы языка / Типы данных / Объект динамического массива - Документация по MQL5
 
220Volt:

double f[] = { 0.0, 0.236, 0.382, 0.5, 0.618, 1.0 }; non-dynamic array.

double f[] is a dynamic array by itself. It is this array that is declared during creation. I haven't analyzed whether it will stop being dynamic after initializing it with the finite initializing sequence. The main thing you've found out above is that the declared array acquires a particular size after initialization.

Are you saying that dynamic array in the result of explicit initialization stops being dynamic, i.e. loses its dynamic status and properties? - Maybe so, but I doubt it. Question: on what grounds (why) does a dynamic array double f[] stop being a dynamic array?

 
Yedelkin:

double f[] is itself a dynamic array. It is declared at creation. I haven't investigated whether it stops being dynamic after initialization by the final initializing sequence. The main thing you've found out above is that the declared array acquires a particular size after initialization.

Are you saying that dynamic array in the result of explicit initialization stops being dynamic, i.e. loses its dynamic status and properties? - Maybe so. Then the question is: why?

The whole point is that we in MKL are a bit "isolated" from the real world )), the compiler decides for us in such a situation. If it sees it:

double f[5];
double f[] = {0, 1, 3};

creates a static array (without the ability to resize it). If it sees it:

double f[];

creates structure struct MqlArrayObject (it behaves as a dynamic array), in global memory. Therefore, you cannot initialize an array after declaration (double f[]; f = {6};)

P.S: all written is my IMHO, I could be wrong somewhere.

 

Question from a dummy: Is it true that if the compiler sees the string

double f[] = {0, 1, 3};

it will initially create a static array instead of a dynamic one?

There is a rule:"When declaring a dynamic array (an array with an unspecified value in the first pair of square brackets), the compiler automatically creates a struct variable MqlArrayObject(a dynamic array object) and provides code for proper initialization. Or is presence of the final initializing sequence equal to "explicitly specifying all the significant array dimensions" and leads to creation of a static array?

 
Yedelkin:

Question from a dummy: Is it true that if the compiler sees the string

it will initially create a static array instead of a dynamic one?

There is a rule:"When declaring a dynamic array (an array with an unspecified value in the first pair of square brackets), the compiler automatically creates a struct variable MqlArrayObject(a dynamic array object) and provides code for proper initialization. Or is presence of the final initializing sequence equal to "explicitly specifying all the significant array dimensions" and leads to creation of a static array?

Is it weak to check it?

;)

 
MetaDriver:

Can't you check?

;)

Not much at the moment. I won't get to the terminal until this evening. Otherwise my answer for 220Volt would have sounded different, as you understand :) I couldn't find the information in the Handbook. Maybe I didn't look hard enough, but meticulously.
 
Yedelkin:
At the moment, it's weak. I won't get to the terminal until this evening. Otherwise my answer to 220Volt would have sounded different, as you understand :) I couldn't find the information in the Handbook. Maybe I wasn't looking hard enough, but I was being meticulous.

OK, I'm out of the terminal. :) I am also outside the terminal.

Checked elementary - trying to use ArrayResize(...)

Документация по MQL5: Операции с массивами / ArrayResize
Документация по MQL5: Операции с массивами / ArrayResize
  • www.mql5.com
Операции с массивами / ArrayResize - Документация по MQL5
Reason: