Precedence Madness

Why does == have higher precedence than &? It took me forever to figure out why my masked comparison wasn't producing the expected result, until I forced the parentheses myself.

Why does == have a higher precedence than &?

It took me forever to figure out why:

if (value1 == value2 & mask)

wasn't producing the expected result. On a whim I forced the order of operations to:

if (value1 == (value2 & mask))

and that's when I realized my error. Comparisons should follow operators and precede the "logics".

Subscribe to A garage sale for your mind

Don’t miss out on the latest posts. Sign up now to get access to the library of members-only posts.
[email protected]
Subscribe