From owner-freebsd-current@FreeBSD.ORG Fri Mar 3 00:45:11 2006 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B2E7E16A420; Fri, 3 Mar 2006 00:45:11 +0000 (GMT) (envelope-from grog@lemis.com) Received: from ext-gw.lemis.com (ext-gw.lemis.com [150.101.14.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6EF2E43D5E; Fri, 3 Mar 2006 00:45:08 +0000 (GMT) (envelope-from grog@lemis.com) Received: from wantadilla.lemis.com (wantadilla.lemis.com [192.109.197.135]) by ext-gw.lemis.com (Postfix) with ESMTP id 122C6131E00; Fri, 3 Mar 2006 11:15:07 +1030 (CST) Received: by wantadilla.lemis.com (Postfix, from userid 1004) id E7BAC85EA0; Fri, 3 Mar 2006 11:15:06 +1030 (CST) Date: Fri, 3 Mar 2006 11:15:06 +1030 From: Greg 'groggy' Lehey To: Dmitry Pryanishnikov , "M. Warner Losh" , Robert Watson Message-ID: <20060303004506.GA13218@wantadilla.lemis.com> References: <4407226D.3050901@freebsd.org> <20060302171112.A77029@fledge.watson.org> <20060302105229.P83093@atlantis.atlantis.dp.ua> <20060302163633.H77029@fledge.watson.org> <4407226D.3050901@freebsd.org> <20060302.100922.130234735.imp@bsdimp.com> <20060302105229.P83093@atlantis.atlantis.dp.ua> <20060302.100608.80501136.imp@bsdimp.com> <20060302105229.P83093@atlantis.atlantis.dp.ua> <200002110637.RAA79715@freebie.lemis.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="pWyiEgJYm5f9v55/" Content-Disposition: inline In-Reply-To: <20060302171112.A77029@fledge.watson.org> <20060302.100922.130234735.imp@bsdimp.com> <20060302.100608.80501136.imp@bsdimp.com> <20060302105229.P83093@atlantis.atlantis.dp.ua> <200002110637.RAA79715@freebie.lemis.com> User-Agent: Mutt/1.4.2.1i Organization: The FreeBSD Project Phone: +61-8-8388-8286 Fax: +61-8-8388-8725 Mobile: +61-418-838-708 VoIP: sip:0871270137@sip.internode.on.net WWW-Home-Page: http://www.FreeBSD.org/ X-PGP-Fingerprint: 9A1B 8202 BCCE B846 F92F 09AC 22E6 F290 507A 4223 Cc: freebsd-current@freebsd.org, cperciva@FreeBSD.ORG Subject: Re: style(9) question X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Mar 2006 00:45:11 -0000 --pWyiEgJYm5f9v55/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thursday, 2 March 2006 at 11:06:31 +0200, Dmitry Pryanishnikov wrote: > > I apologize for asking here my question (it should belong to -questions, > but the most developers are available here, and I just hope it won't hurt). > What's the historical reason of the following style(9) advise: > > Values in return statements should be enclosed in parentheses. The background is "that's the way our grandfathers did it". I asked dmr about this some years ago. Here his reply: On Friday, 11 February 2000 at 1:36:53 -0500, Dennis Ritchie wrote: >> I've been wondering about the tradition of writing 'return >> (expression)' instead of 'return expression' in C code. The earliest >> documentation I have (K&R I) suggests I use the former (page 68), >> without specifying why, while appendix A (page 218) specifies 'return >> expression'. >> >> I got hold of last1120 This is the last version of the C compiler written for the PDP 11/20, some time in 1972. >> and compiled and ran it against a test program, and it seems that >> this version won't accept the syntax 'return expression': the >> parentheses are mandatory. Would it be fair to consider the usage >> 'return (expression)' as an archaism? > > An archaism: just so. The language and compiler ca. 1973 > did want the parens. By the 5th edition (1975) I had realized that > they weren't needed and the syntax was just 'return expression'. > > On the other hand, no one seemed to want to make use of the > new freedom. I glanced at v7 source (1977) and couldn't > find any instances of non-parenthesized return values-- > I might have missed an instance, but there couldn't have > been more than a very few. Evidently it had become wired > into the mental syntax. > > This was certainly true for Brian in K&R 1 and evidently > for me as well, since the very few examples in the appendix > use the (). But the grammar does indeed reflect the > fact that they weren't required. > > Dennis On Thursday, 2 March 2006 at 10:06:08 -0700, M. Warner Losh wrote: > > No. Debates over style(9) aren't productive. Agreed. On Thursday, 2 March 2006 at 10:09:22 -0700, M. Warner Losh wrote: > In message: <4407226D.3050901@freebsd.org> > Colin Percival writes: >> Robert Watson wrote: >>> I can't really think of a good reason >>> for return (foo) over return foo >> >> I'm not sure if this qualifies as a *good* reason, but >> writing "return (foo)" is more consistent with other >> keyword usage: "if (foo)", "for (foo)", "while (foo)", >> "switch (foo)". > > Before 'void' existed, many people recommended () so that you could > make 'return' a macro for extra debugging. With void functions that > have naked returns make this impossible these days... This is actually a useful property. Pity it's gone. On Thursday, 2 March 2006 at 17:12:09 +0000, Robert Watson wrote: > On Thu, 2 Mar 2006, Colin Percival wrote: > >> Robert Watson wrote: >>> I can't really think of a good reason >>> for return (foo) over return foo >> >> I'm not sure if this qualifies as a *good* reason, but writing "return >> (foo)" is more consistent with other keyword usage: "if (foo)", "for >> (foo)", "while (foo)", "switch (foo)". > > I also find myself doing search and replace on return values more on > FreeBSD source than I do on other source. I.e.: s/return (0)/return > (NULL)/ and that sort of thing. I think I would be less comfortable doing > that without the parens. Why? This sounds like the MySQL argument for writing: foo= bar; instead of foo = bar; Greg -- See complete headers for address and phone numbers. --pWyiEgJYm5f9v55/ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (FreeBSD) iD8DBQFEB5GSIubykFB6QiMRAmK4AKCR2YqygL2s0D4JHY0dom+qtG7SVgCbByYV savMs8jmFfT9rSFTBwVPmY4= =97rn -----END PGP SIGNATURE----- --pWyiEgJYm5f9v55/--