Go Down

Topic: Documentation request: operator precedence (Read 1 time) previous topic - next topic

odometer

I notice that the Arduino Reference, here:
http://arduino.cc/en/Reference/HomePage
does not seem to contain any information about operator precedence (at least, not where I could find it easily).

Not knowing about operator precedence led me to make huge bugs.
For example, I used (x&15>9) for intended ((x&15)>9).

Nick Gammon

You can Google "C++ operator precedence" but I agree, a mention on the Reference page would be nice.

odometer


You can Google "C++ operator precedence" but I agree, a mention on the Reference page would be nice.


Here is what I am trying to understand:
The Reference page has information on these operators, among others: + - * / % = ==
I see that you explain the use of these operators, rather than assuming that we are familiar with them from having used C++. Also, you volunteer this explanation, rather than simply referring us to a (non-Arduino-specific) C++ reference.
What I don't understand is a philosophy that reckons it worthwhile to explain the use of the operators, but considers it less than obligatory to even mention that these operators have an order of precedence, much less detail what that order is, exactly.

WizenedEE



You can Google "C++ operator precedence" but I agree, a mention on the Reference page would be nice.


Here is what I am trying to understand:
The Reference page has information on these operators, among others: + - * / % = ==
I see that you explain the use of these operators, rather than assuming that we are familiar with them from having used C++. Also, you volunteer this explanation, rather than simply referring us to a (non-Arduino-specific) C++ reference.
What I don't understand is a philosophy that reckons it worthwhile to explain the use of the operators, but considers it less than obligatory to even mention that these operators have an order of precedence, much less detail what that order is, exactly.


The order of most operations is the same as normal (PEMDAS), so it's intuitive for those new to arduino. Knowing that the language has them is not. Once you get into bitwise arithmetic you're advanced enough to know where to look it up.

DuaneB

Hi

Just to keep you and anyone you want to share your code with sane, you can use the ( ) as you did to illustrate your confusion in the first post, it doesn't generate any additional code and ensures you get the results you wanted.

Duane B


Go Up