objective c - Why use double parentheses in init methods, or is 1 == (1)? -
what parentheses when evaluating meaning? have faced in code, when checked , use
if ( (some condition returns 1) ) { code }
so question is, evaluate true? think false since (1) not return anything?
edit: clarification, question why double parenthesis in if? know 1 true.
the additional parentheses used when assignment used truth value. allow compiler distinguish between
if ((var = expr))
as legitimate combination of assignment , truth value test, and
if (var = expr)
as misspelling of if (var == expr)
.
the convention, carried on c , c++, compilers warn on if (var = expr)
possible misspelling of if (var == expr)
. don't warn on if ((var = expr))
, because set of parentheses signals compiler assignment intended. rob mayoff explains, clang has special case not warn assignments self
, many coders habit remained.
as others said, generated code same , without parens.
Comments
Post a Comment