From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28306 invoked by alias); 20 Dec 2007 15:09:35 -0000 Received: (qmail 28098 invoked by uid 22791); 20 Dec 2007 15:09:34 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 20 Dec 2007 15:09:24 +0000 Received: (qmail 30254 invoked from network); 20 Dec 2007 15:09:22 -0000 Received: from unknown (HELO 81-178-222-163.dsl.pipex.com) (paul@127.0.0.2) by mail.codesourcery.com with ESMTPA; 20 Dec 2007 15:09:22 -0000 From: Paul Brook To: gcc@gcc.gnu.org Subject: Re: -Wparentheses lumps too much together Date: Thu, 20 Dec 2007 16:41:00 -0000 User-Agent: KMail/1.9.7 Cc: "James K. Lowden" , Ian Lance Taylor References: <20071219200235.GA21525@oak.schemamania.org> <20071220005030.4971a442.jklowden@freetds.org> In-Reply-To: <20071220005030.4971a442.jklowden@freetds.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200712201509.20582.paul@codesourcery.com> Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2007-12/txt/msg00629.txt.bz2 > My untested (and consequently firmly > held) hypothesis is that > > 1) most combinations of && and || don't need parentheses because > > (a && b) || (c && d) > > is by far more common than > > a && (b || c) && d > > and, moreover, broken code fails at runtime, and I dispute these claims. The former may be statistically more common, but I'd be surprised if the difference is that big. I can think of several fairly common situations where both would be used. Any time you've got any sort of nontrivial condition, I always find it better to include the explicit parentheses. Especially if a, b, c, and d are relatively complex relational expressions rather than simple variables. Code failing at runtime is way too late. By that time it's already been burned onto the device, and may be half way to the moon :-) Coverage testing never tests everything, and there's a fair chance that your complex condition will only break in an exceptional case which is, by definition, hard to predict, test and reproduce. > 2) Most programmers know (because they need to know) that && comes > before ||. I don't really believe that either. Most *good* programmers know operator precedence rules (or will at least look it up). However there are a lot of distinctly average programmers, and even the good programmers get confused or have bad days. As someone else mentioned precedence of arithmetic operators is taught in school from a fairly early age. Precedence of logical operators is (to me at least) much less well conditioned. I have no objection to splitting -Wparentheses into finer grained options. I just think they should remain enabled by -Wall. Paul