This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: suggest parentheses around assignment used as truth value



> 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.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]