unbelievable :) Even in MT5!
well, it's the way the cpp compiler analyses and executes expressions, it obviously performs pre-increment first on the whole expression.
whether this is a bug or not, depends on the definition of the cpp standard which MQ doesn't follow completely anyway, so it can be interpreted either way. perhaps it is even a bug in optimizer. it is not so uncommon situation, although i haven't seen this behaviour on dozens of c/cpp compilers in almost 30 years :)
however if you use this kind of expressions, it's your own fault: you will have bugs and unpredicted situations in your code.
expressions have to be clean, without pre and post increments if you are using same variable more than once in the expression, with lots of brackets to clearly define the priority of operations etc.
otherwise you will have Don Quixote's issues.
ihao: Print(++i + ++i); // result is "4" not "3" |
|

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
when i do some test with mql4 by this script:
int i = 0;
Print(i++ + i++); // result is "1"
i = 0;
Print(++i + ++i); // result is "4" not "3"
and i had do the same thing in JavaScript, "++i + ++i" => 3;
is that a bug?