Hello,
I have come accross a strange behaviour and would like to get some feedback on this.
Shouldn't this be valid code??
The compiler complains warning: "result of expression not used" which is not correct, becauses it is used and it works...
((test1) || ((test2) && (MyConditionFunc() == 1)) ) && MyTestFunc();
what is that supposed to do ?
try using the IF statement and then do something based upon the outcome
Thank you for your answer, the issue is not what it is supposed to do, but as a short description, this is an unconditional code.
The issue lies within the fact, the compiler gives a warning, although it should not. - This is my concern with this code. The code itself works perfectly and exactly as expected.
I suspect in fact an issue within the compiler. but since I am not suree, I want to ask the community for support.
BTW: The code has been written like this to not use if-statements. - if-statements can be quite slow.
Thank you for your answer, the issue is not what it is supposed to do, but as a short description, this is an unconditional code.
The issue lies within the fact, the compiler gives a warning, although it should not. - This is my concern with this code. The code itself works perfectly and exactly as expected.
I suspect in fact an issue within the compiler. but since I am not suree, I want to ask the community for support.
BTW: The code has been written like this to not use if-statements. - if-statements can be quite slow.
it's nonsense imo even if you say it is an expression and not an if, you are not using the outcome of the expression so it is pointless.
so either use it or or store it, but just processing an expression without is wasted processing hence the compiler warning you have
I am sorry to say this, but that is untrue.
Go through and test yourself.
The code will conditionally break out into the subfunctions without disturbing the current flow of the function where this code is inserted. - No conditional break within the code flow of the function, if not necessary.
Thats the point of this code, it is valid, it works and it is about 10 times faster than an if-statement. - But thats not the point of discussion here. Its about this code giving a warning, while following does not:
long MyConditionFunc() { return(2); } bool MyTestFunc() { return(true); } void OnInit() { bool test1 = true; bool test2 = false; (test1) && MyTestFunc(); return(INIT_FAILED); }
Now tell me, how do you explain that??
I am sorry to say this, but that is untrue.
Go through and test yourself.
The code will conditionally break out into the subfunctions without disturbing the current flow of the function where this code is inserted. - No conditional break within the code flow of the function, if not necessary.
Thats the point of this code, it is valid, it works and it is about 10 times faster than an if-statement. - But thats not the point of discussion here. Its about this code giving a warning, while following does not:
I am sorry to say this, but that is untrue.
Go through and test yourself.
The code will conditionally break out into the subfunctions without disturbing the current flow of the function where this code is inserted. - No conditional break within the code flow of the function, if not necessary.
Thats the point of this code, it is valid, it works and it is about 10 times faster than an if-statement. - But thats not the point of discussion here. Its about this code giving a warning, while following does not:
Now tell me, how do you explain that??
Now tell me, how do you explain that??
you have removed the condition check ==1 so now it is just processing and not preforming an expression with nowhere to assign or use the answer, so you will get no warning
best way to describe it is:
All the time you are just using boolean logic it is fine, but you have added in a numerical comparison of the value 1 to that of a function output.
The compiler is now saying this is an expression with an answer and you are not using it so it is warning you of that, like you say it still works in practice because each function is processed subject to the logic.
I would say IMO that the warning given my MetaEditor is just not sufficiently clear or can be misunderstood.
Your code is definitely valid code as per the normal "C" usage, but MQL is slightly different in the way it works compared to "C". It may not like to have pure expressions left unused.
That line of the code would be considered as a pure expression, and in "C" that would be fine, but it is not assignment to anything or consumed by a function parameter and that is what the warning is about.
So, the expression is been evaluated, and it is only the final result of the expression that is been considered "unused" (not the individual parts of the expression nor the expression itself), as the warning states:
- "result of expression not used"
EDIT: In order words, its expecting something like this:
some_bool_variable = ((test1) || ((test2) && (MyConditionFunc() == 1)) ) && MyTestFunc(); // Assignment or ... SomeFunction( ((test1) || ((test2) && (MyConditionFunc() == 1)) ) && MyTestFunc() ); // Consumed as an argument for a function parameter
EDIT2: It is only a warning, so I would not worry too much as long as you understand why the compiler gives that warning.
PS! I too like using expressions to speed up things like you did, but I usually always assign the final result, so never noticed that warning before.
You are welcome!
Given that MQL is a strange implementation of "C", like everything MetaQuotes, you will probably never figure out the reason why one gives a warning and the other not. And even if you do, it will probably not make much sense.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I have come accross a strange behaviour and would like to get some feedback on this.
Shouldn't this be valid code??
The compiler complains warning: "result of expression not used" which is not correct, becauses it is used and it works...