Unnecessary parenthesis
Chris Torek
chris at mimsy.UUCP
Sat Jul 2 18:13:29 AEST 1988
In article <326 at marob.MASA.COM> daveh at marob.MASA.COM (Dave Hammond) writes:
>Is different code produce by the compiler for "return n" and "return(n)" ?
>How about "if (x>1 && y<2)" and "if ((x>1) && (y<2))" ? Do unnecessary
>parenthesis generate more code ?
For these expressions, one would hope not.
On some machines, in certain expressions (including but not limited
to floating point arithmetic), `unnecessary' parentheses may cause
more code generation under dpANS rules:
#define TWICE(x) ((x) + (x))
...
float p, q, r;
...
r = TWICE(p + q);
expands to
r = ((p + q) + (p + q));
which might or might not be equivalent to
r = p + p; r += q + q;
and if this cannot be determined, must be compiled as
r = p + q; r += p + q; /* more or less */
The important problem that is being solved is that
a = (b + c) * d;
might give 0.0 where
a = (b * d) + (c * d);
gives `floating point overflow'. Whether this is an ideal solution
(or even a not-too-awful one) is another argument entirely....
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list