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
MqlRates mrate[];//массив нулевого размера
Use ArrayResize and ArrayInitialize.
Usually with CopyRates this structure is used.
Renat said it was better to do it like this:
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:
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:
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:
Will it cause an error?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.
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?
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:
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
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?
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?
;)
Can't you check?
;)
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(...)