× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Dan -

Um, I think you just agreed with me, Scott. I said the parantheses guaranteed that it would be done first, whereas Doug, the author of that snippet, said otherwise.

The thing that you and everyone else seems to be overlooking is that the precedence order in the source and the code generated by the compiler to apply that precedence are two different things.


The precedence guarantees that things with a higher precedence, whether due to parenthesis or the precendence of operations list, will be processed before anything that relies on them is processed.

If there is an eval or if with only one thing in parenthesis, that does NOT mean that that one thing will be processed first.

The compiler looks at the expression and can determine what parts depend on other parts and builds the code so as to avoid doing any unnecessary work.

I<=%ELEM(ARRAY) AND I>0 AND ARRAY(I)>10

The compiler can determine that if the first condition is false, it doesn't need to check the second and third, or if the first is true and the second is false, it doesn't need to check the third. That's why this code will prevent an array index error if I is out of range of the array.


The precedence of operators means that the compiler treats it as:

((I <= %ELEM(ARRAY)) AND (I > 0)) AND (ARRAY(I) > 10)

rather than:

((I <= (%ELEM(ARRAY) AND I)) > (0 AND ARRAY(I))) > 10

which is what would happen if AND and OR were moved higher than compares.

Ken
http://www.ke9nr.net/
Opinions expressed are my own and do not necessarily represent the views of my employer or anyone in their right mind.



As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.