Originally Posted by
dwks
I don't.
Code:
if (a <= x && x <= y) {}
is perfectly readable as far as I am concerned . . . but if you don't think so, then by all means use parentheses.
It's a common enough idiom.
Yes, that particular example is fine, but it you start getting into more complex expressions and start using different operators, you might run into problems, especially where precedence is concerned. So I choose to always be explicit with parentheses so I don't have to remember when it's safe not to use them...
I've seen some code that did something like this:
Code:
if ( ptr = func() == NULL )
and from the context it looks like the person who wrote it intended it to mean:
Code:
if ( (ptr = func()) == NULL )
but because of precedence it actually meant:
Code:
if ( ptr = (func() == NULL) )