Why use double parentheses in init methods, or is 1 == (1)?
c, objective-c
Solution
The additional parentheses are used when an assignment is used for its truth value. They allow the compiler to distinguish between
if ((var = expr))
which signals intentional combination of assignment and truth value test, and
if (var = expr)
as an unintentional misspelling of `if (var == expr)`.
The convention, carried over from C and C++, is for the compilers to warn on `if (var = expr)` as a possible misspelling of `if (var == expr)`. They don't warn on `if ((var = expr))`, because the extra set of parentheses signals to the compiler that the assignment was intended. As rob mayoff explains, clang has a special case not to warn for certain assignments to `self`, but for many coders the habit remained.
As others said, the generated code is exactly the same with and without the extra parens.
Problem
What do parentheses do when evaluating some meaning? I have faced this in code, when something is checked and they use ``` if ( (some condition that returns 1) ) { code } ``` So my question is, does this evaluate to true? I would think that it is always false since (1) does not return anything? Edit: clarification, question is why double parenthesis in if? I know that 1 is true.