Probably because the compiler does unrole and reduces it to a single assignment line....
Then it's a compiler error.
Try using a random number instead of incrementing by 1.
Replacing it with MathRand, which logically is never called, makes a non-zero value. This further supports the hypothesis that zero is a compiler error.
Replacing it with MathRand, which logically is never called, makes a non-zero value. This further supports the hypothesis that zero is a compiler error.
Maybe... Not sure about that. But only because you don't initialize MqlTick.
But I guess the compiler looks at it like this:
Function f2 evaluates to 0 in all cases in your code, so the for loop is with no effect, and therefore gets cut out and replaced with one single assignment.
Because f2 tmp is NOT zero, and therefore will return tick unmodified.
Compiler probably assumes you want MqlTick to be all zero, therefore it will evaluate to zero under all circumstances.
The assumption by the compiler MqlTick being zero is where the "bug" probably is, as far as this can be considered a bug, and not an oversight by the coder, which gets corrected by the compiler.
Dominik Egert #: How do you know it will be initialised? Won't it just be filled with values? Or is that what you mean by "initialised".
I don't know, I'm relying on the docs. It says that the structure must be filled. But if a value is not assigned to a field in the function being called, we get a UB when we get the value of that field later.
fxsaber #: It doesn't. For example, swap the Bench1 and Bench2 calls.
I still think the compiler reduces the for loop to one line...
Actually, maybe the compilers optimizer misses out on the optimization on the static variable, due to it coming from a different memory region, and therefore might assume, it is not local and could be changed externally, like a buffer by the terminal.
Or, optionally, the code is actually working as expected, but it is optimized into a register and so fast, we cannot measure it with micros.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Probably because the compiler does unrole and reduces it to a single assignment line....
Replacing it with MathRand, which logically is never called, makes a non-zero value. This further supports the hypothesis that zero is a compiler error.
Then it's a compiler error.
Replacing it with MathRand, which logically is never called, makes a non-zero value. This further supports the hypothesis that zero is a compiler error.
Why?
Why?
How do you know it will be initialised? Won't it just be filled with values? Or is that what you mean by "initialised".
I don't know, I'm relying on the docs. It says that the structure must be filled. But if a value is not assigned to a field in the function being called, we get a UB when we get the value of that field later.
Tried it.
Result.
Frankly speaking, I don't understand why the second line gets zero when there is no initialisation.
This is UB behaviour. Since you return the value of the field, the compiler thinks you have initialised it, the only place where you do that is
Tick.time = 1;Accordingly, your entire function is reduced by the optimiser to
It doesn't. For example, swap the Bench1 and Bench2 calls.
This is the behaviour under UB. Since you return the value of the field, the compiler assumes you have initialised it, the only place you do that is
Consequently, your entire function is reduced by the optimiser to
Parity.