I'm sure we all know this, but just sometimes get confused when under
fire or when adding an additional term to an existing expression. 

* and / have equal precedence with each other, and + and - have equal
precedence with each other. But && has a higher precedence than || and &
has a higher precedence than | so...

X && Y || Z is equivalent to (X && Y) || Z, not X && (Y || Z)
and 
X | Y & Z is equivalent to X | (Y & Z), not (X | Y) & Z

The most common incorrect pattern is basically along the lines of

if (pPointer && pPointer->IsSomething() || pPointer->IsOther())

Because I can't get quite enough pain in my life I've checked the
results of a gcc 4.3.2 -Wparentheses on all the warnings-free modules
and logged patches for the very dubious looking ones where the
whitespacing of the expression or the symmetry of terms makes me suspect
the intent isn't what is actually expressed. 

(Though for any expressions where there are about 20+ terms in a
potentially ambiguous expression I just closed my eyes)

Precedence Reference Tables:
http://www.cppreference.com/wiki/operator_precedence
http://www.difranco.net/cop2220/op-prec.htm

C.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to