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: rouaix at my-dejanews dot com
- Subject: Re: suggest parentheses around assignment used as truth value
- From: "Brad M. Garcia" <bgarcia at fore dot com>
- Date: Wed, 1 Jul 1998 07:02:11 -0400 (EDT)
- cc: egcs at cygnus dot com
> 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.