Unnecessary parentheses (Was: Help: VAX C problem)
Joseph Schwartz
xor at aix01.aix.rpi.edu
Tue Apr 2 15:11:26 AEST 1991
In article <1991Apr1.203600.15721 at zoo.toronto.edu> henry at zoo.toronto.edu (Henry Spencer) writes:
>In article <4072.27f7215c at iccgcc.decnet.ab.com> browns at iccgcc.decnet.ab.com (Stan Brown) writes:
>>I bet if you stopped 100 C programmers, more than 50 of 'em would tell
>>you that parentheses are part of the return statement, just like if,
>>while, do, and for. They're not.
>
>They used to be, actually, and many of the role models :-) for C programmers
>have habits dating back to the time when they were.
Is this true? The grammar in K&R1 (pg 218) does not require parens in the
return statement. However, the example on page 68 (and indeed all of the
examples in the book) show the parentheses around the expression.
Another place I tend to see unnecessary parens is with the sizeof
operator. You can use "sizeof (typename)" or "sizeof expression"...
I often see "sizeof (expression)"...usually there's no space between
the sizeof and the left paren, which may reinforce the belief that
the parens "belong to" the sizeof operator.
Just curious...how often do you folks purposely insert unnecessary parens
into expressions? Sometimes I'll do it just to make the grouping clearer
(just in case the next person to read the code doesn't know all the
precedence rules by heart). I'm talking about expressions in general,
not just in conjunction with return or sizeof.
--
Joe Schwartz
Internet: xor at mts.rpi.edu
Bitnet: userez3n at rpitsmts
More information about the Comp.lang.c
mailing list