Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!rpi!xor From: xor@aix01.aix.rpi.edu (Joseph Schwartz) Newsgroups: comp.lang.c Subject: Unnecessary parentheses (Was: Help: VAX C problem) Message-ID: <1#.gqcm@rpi.edu> Date: 2 Apr 91 05:11:26 GMT References: <1991Mar30.161854.27378@cbnewsk.att.com> <4072.27f7215c@iccgcc.decnet.ab.com> <1991Apr1.203600.15721@zoo.toronto.edu> Organization: Rensselaer Polytechnic Institute, Troy NY Lines: 29 Nntp-Posting-Host: aix01srv.aix.rpi.edu In article <1991Apr1.203600.15721@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: >In article <4072.27f7215c@iccgcc.decnet.ab.com> browns@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@mts.rpi.edu Bitnet: userez3n@rpitsmts