From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Brad M. Garcia" To: rouaix@my-dejanews.com Cc: egcs@cygnus.com Subject: Re: suggest parentheses around assignment used as truth value Date: Wed, 01 Jul 1998 04:00:00 -0000 Message-id: X-SW-Source: 1998-07/msg00029.html > I'd just like to register my opiniont that code like > > if (x = p()) {...} > > shouldn't generate a warning under gcc -Wall. Even if > you feel that code like this is obscure, the recommended > > if ((x = p())) {...} > > is just bizarre. In 80% (don't you love making up statistics?) of cases where "=" is used inside an "if" expression, the programmer meant to use "==". So the warning is helpful. Now, it "suggests" using parentheses as a means to bypass the generation of this warning. You don't need to follow the suggestion, but the suggestion results in the least amount of change to the source code. Other methods include moving the assignment outside of the "if" expression, or using -Wno-parentheses in addition to -Wall. Brad Garcia ___/ __ / __ / ___/ "Being the Linux of digital media __/ / / / _/ __/ would be a very good life." _/ ____/ _/ _| ____/ - Jean-Louis Gassee, CEO of Be, Inc.