Path: utzoo!attcan!uunet!husc6!mailrus!nrl-cmf!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Unnecessary parenthesis Message-ID: <8209@brl-smoke.ARPA> Date: 2 Jul 88 18:29:59 GMT References: <326@marob.MASA.COM> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 27 In article <326@marob.MASA.COM> daveh@marob.UUCP (Dave Hammond) writes: >Do unnecessary parenthesis generate more code ? The answer used to be, "not using any reasonable compiler". Under the new ANSI C honoring-parentheses rule, excessive parentheses CAN interfere with code optimization, when they occur in a context that might have been rearranged if the parentheses had not been present. My main objection to excessive parentheses is that they make the code less readable, not more. There are a few cases where the C precedence rules run counter to intuition, and in such cases sparing use of technically redundant parentheses can help the code reader. However, they should not be used just because the code WRITER is unsure. (Most C programmers I know have a copy of the chart from K&R 1st Ed. p. 49 taped up near their terminal.) if ( a < b && b < c ) /* intuitive */ if ( (a < b) && (b < c) ) /* no better */ if ( a << b ^ c | d ) /* have to look this up */ if ( ((a << b) ^ c) | d ) /* no question here */ return 0; /* intuitive */ return(0); /* one wonders why the () are there */