Actions

EmSys

CCoding Style - Parenthesize to resolve ambiguity2

From EdWiki

Revision as of 09:30, 23 June 2015 by Jshankar (Talk | contribs) (1 revision imported: EdWiki -- Emsys pages from Shukra)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Parenthesize to resolve ambiguity ...

The bit wise operators & and ! have lower precedence than relational operations like ==, so despite its appearance,

if( x & MASK == BITS )

actually means

if( x & (MASK == BITS ) )

which is certainly not the programmer’s intent

if( (x & MASK) == BITS )