This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -Wparentheses lumps too much together
- From: Daniel Jacobowitz <drow at false dot org>
- To: jklowden at freetds dot org
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 19 Dec 2007 15:14:26 -0500
- Subject: Re: -Wparentheses lumps too much together
- References: <20071219200235.GA21525@oak.schemamania.org>
On Wed, Dec 19, 2007 at 03:02:35PM -0500, jklowden@freetds.org wrote:
> My specific candidate for exclusion from -Wall is this one:
>
> if (a && b || c && d)
>
> which yields (as you know) advice to parenthesize the two && pairs.
>
> I very much think this is unhelpful, counterproductive advice.
> Yes, I know beginners get confused by and/or precedence. But
> *every* language that I know of that has operator precedence places
> 'and' before 'or'. More important, a C programmer will encounter
> many thousands such expressions in his dealings with the language.
> To "help" him is merely to retard his education.
I am happy to stand as a counterexample; I am an experienced C
programmer and I greatly appreciate this warning. And I loathe
reading code which cavalierly assumes you remember the precedence. +
and *, sure, you learn that in grade school. && and || is trickier
because there are sensible arguments for both directions; it is
harder to derive from first principles.
If you are more bothered by any clarifying parentheses than I am,
use -Wno-parentheses.
--
Daniel Jacobowitz
CodeSourcery