From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Earnshaw To: Bill Currie Cc: rearnsha@sun52.arm.com Subject: Re: suggest parentheses around assignment used as truth value Date: Thu, 02 Jul 1998 07:08:00 -0000 Message-id: <199807021119.MAA19946@sun52.NIS.cambridge> References: <359B0985.2FB4@tssc.co.nz> X-SW-Source: 1998-07/msg00084.html > 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.