Unnecessary parenthesis

Doug Gwyn gwyn at brl-smoke.ARPA
Sun Jul 3 04:29:59 AEST 1988


In article <326 at marob.MASA.COM> daveh at 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 */



More information about the Comp.lang.c mailing list