'warning'에 해당되는 글 1건

  1. 2007/03/23 suggest parentheses around assignment used as truth value
http://gcc.gnu.org/ml/gcc/1998-07/msg00085.html

Re: suggest parentheses around assignment used as truth value

  • To: rouaix at my-dejanews dot com (Marc Rouaix)
  • Subject: Re: suggest parentheses around assignment used as truth value
  • From: Carlo Wood <carlo at runaway dot xs4all dot nl>
  • Date: Wed, 1 Jul 1998 14:50:29 +0200 (CEST)
  • Cc: egcs at cygnus dot com (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.
|
| ---
| 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>


TAG warning