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: Marc Rouaix <rouaix at my-dejanews dot com>
- Subject: Re: suggest parentheses around assignment used as truth value
- From: Branko Cibej <branko dot cibej at hermes dot si>
- Date: Wed, 01 Jul 1998 12:31:21 +0200
- Cc: egcs at cygnus dot com
- Organization: HERMES SoftLab
- References: <JMDHPDCIACOECAAA@my-dejanews.com>
Marc Rouaix wrote:
> I'd just like to register my opiniont that code like
>
> if (x = p()) {...}
>
> shouldn't generate a warning under gcc -Wall.
What if you meant to write "if (x == p()) {...}"? Such bugs are
usually very hard to find.
> Even if you feel that code like this is obscure,
It is _not_ obscure, it is in fact used quite often; therefore the
possibility of a typo is large enough to warrant a warning.
> the recommended
>
> if ((x = p())) {...}
>
> is just bizarre.
Can you recommend a better way of telling the compiler that you know
what you're doing? I mean, apart from the obvious
x = p(); if (x) {...}
Brane
--
Branko Cibej <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
phone: (++386 61) 186 53 49 fax: (++386 61) 186 52 70