This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: suggest parentheses around assignment used as truth value
- To: Bill Currie <bcurrie at tssc dot co dot nz>
- Subject: Re: suggest parentheses around assignment used as truth value
- From: Richard Earnshaw <rearnsha at arm dot com>
- Date: Thu, 02 Jul 1998 12:19:09 +0100
- Cc: Andreas Schwab <schwab at issan dot informatik dot uni-dortmund dot de>, Marc Rouaix <rouaix at my-dejanews dot com>, egcs at cygnus dot com
- Cc: rearnsha at sun52 dot arm dot com
- Organization: Advanced RISC Machines Ltd.
- Reply-To: richard dot earnshaw at arm dot com
> Richard Earnshaw wrote:
> > if ((x = p()) != 0) {...}
> >
> > Then it becomes clear why the extra parentheses are needed.
>
> Yes, because without the parentheses, it will be evaluated as:
>
> if (x = (p() != 0)) {...}
>
> And you're right back where you started from with a `suggest parentheses
> around assignment used as truth value' warning.
>
Of course the parentheses are necessary in that case, but the meaning is
obvious, and the compiler can tell that a warning is unnecessary.
In my opinion, it's a bug if gcc doesn't emit a warning for
if ((x = p())) {...}
but does for
if (x = p()) {...}
since apart from an extra set of parentheses they are identical. Perhaps
the warning should be changed to "suggest explicit comparison of
assignment used as truth value".
Richard.