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

It is a very common mistake to type '=' where '==' was intended.
Using extra parentheses is a very logical way to make the code
more clear in what you mean.  Not only for the author itself,
but also for others that read the code later and wonder if this
is a typo/bug, or if it was intended (something not always clear
from the context).

My personal opinion is that this warning is so useful that I'd
even object to move it to -pedantic warnings.

-- 
 Carlo Wood  <carlo@runaway.xs4all.nl>


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