Unnecessary parentheses (Was: Help: VAX C problem)

Henry Spencer henry at zoo.toronto.edu
Wed Apr 3 04:52:04 AEST 1991


In article <1#.gqcm at rpi.edu> xor at aix01.aix.rpi.edu (Joseph Schwartz) writes:
>>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.

It's true.  A lot of us Real Old Timers remember when K&R1 came out.  The
parentheses stopped being mandatory somewhat before that.  BWK and DMR
picked up the habit when they were still required, as did others.

>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)"...

I think this is a combination of (a) paranoia about operator precedence,
and (b) a general feeling that treating this funny operator as if it were
a function gives a cleaner appearance.

>Just curious...how often do you folks purposely insert unnecessary parens
>into expressions?  Sometimes I'll do it just to make the grouping clearer...

Parentheses inserted to make grouping clearer are "unnecessary" only to
the compiler; almost nobody really has the C precedence rules memorized.
-- 
"The stories one hears about putting up | Henry Spencer @ U of Toronto Zoology
SunOS 4.1.1 are all true."  -D. Harrison|  henry at zoo.toronto.edu  utzoo!henry



More information about the Comp.lang.c mailing list