public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* suggest parentheses around assignment used as truth value
@ 1998-06-30 19:49 Marc Rouaix
  1998-07-01  2:51 ` Andreas Schwab
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Marc Rouaix @ 1998-06-30 19:49 UTC (permalink / raw)
  To: egcs

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



-----== Sent via Deja News, The Discussion Network ==-----
http://www.dejanews.com/  Easy access to 50,000+ discussion forums

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: suggest parentheses around assignment used as truth value
@ 1998-07-01  4:00 Brad M. Garcia
  1998-07-01 20:20 ` Tim Hollebeek
  1998-07-02  1:39 ` Harvey J. Stein
  0 siblings, 2 replies; 13+ messages in thread
From: Brad M. Garcia @ 1998-07-01  4:00 UTC (permalink / raw)
  To: rouaix; +Cc: egcs

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


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~1998-07-03 14:48 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-30 19:49 suggest parentheses around assignment used as truth value Marc Rouaix
1998-07-01  2:51 ` Andreas Schwab
1998-07-01  9:20   ` Richard Earnshaw
1998-07-01 21:20     ` Bill Currie
1998-07-02  7:08       ` Richard Earnshaw
1998-07-03  3:31         ` Nathan Sidwell
1998-07-03  6:15           ` Richard Earnshaw
1998-07-01  3:42 ` Branko Cibej
1998-07-02  7:08 ` Carlo Wood
1998-07-03 14:48   ` Kamil Iskra
1998-07-01  4:00 Brad M. Garcia
1998-07-01 20:20 ` Tim Hollebeek
1998-07-02  1:39 ` Harvey J. Stein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).