Associativity in Objective-C

I still remember my old days in HKU where Dr Choi gave us lecture on precedence and associativity. Well, I should say, luckily, I haven’t forgotten that completely :P

Here’s what I write in my code:

reading[idx] – 1 < 0 ? 9 : reading[idx] – 1

The compiler interprets this as: ( reading[idx] – 1 < 0 ? 9 : reading[idx] ) – 1

This is not the behaviour I want though. What I want is: reading[idx] – 1 < 0 ? 9 : (reading[idx] – 1)

You can refer to C++ Reference for reference to operator precedence and associativity.

Have fun hacking :)