This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -Wparentheses lumps too much together
- From: Robert Dewar <dewar at adacore dot com>
- To: Joe Buck <Joe dot Buck at synopsys dot COM>
- Cc: Rehno Lindeque <errantkid at gmail dot com>, Ross Smith <r-smith at ihug dot co dot nz>, gcc at gcc dot gnu dot org
- Date: Fri, 11 Jan 2008 12:04:08 -0500
- Subject: Re: -Wparentheses lumps too much together
- References: <20071219200235.GA21525@oak.schemamania.org> <m3hciewav7.fsf@localhost.localdomain> <20071220005030.4971a442.jklowden@freetds.org> <200712201509.20582.paul@codesourcery.com> <476C1461.2050107@ihug.co.nz> <c10d42150801102334i27ef4achcff6a64cf6e356c@mail.gmail.com> <20080111165936.GB31668@synopsys.com>
Joe Buck wrote:
On Fri, Jan 11, 2008 at 09:34:29AM +0200, Rehno Lindeque wrote:
Just a note: Operator precedence is taught as logical AND comes before
OR in logic courses. So it is a sort of a standard mathematical
convention just like + and *. In fact, OR is even represented as a +
in some notations. However it might not be practical to assume all
programmers have a background in logic.
A warning that flagged code like
if (c1 || c2 && c3)
...
would swamp users in warnings, since this kind of code is extremely
common, and this isn't the kind of thing that anyone who's not a total C
beginner has trouble with.
I find it a valuable warning, I think it is a mistake to rely on
dubious precedence for cases like this (dubious because the analogy
of || and && with + and * is stretching things).
I must say I prefer the Ada syntax here, which prohibits mixing
of different logical operators in this way.