From owner-freebsd-questions Tue May 15 20:13: 8 2001 Delivered-To: freebsd-questions@freebsd.org Received: from wantadilla.lemis.com (wantadilla.lemis.com [192.109.197.80]) by hub.freebsd.org (Postfix) with ESMTP id 08ABA37B424 for ; Tue, 15 May 2001 20:13:03 -0700 (PDT) (envelope-from grog@lemis.com) Received: by wantadilla.lemis.com (Postfix, from userid 1004) id 0B4DA6ACBC; Wed, 16 May 2001 12:43:00 +0930 (CST) Date: Wed, 16 May 2001 12:43:00 +0930 From: Greg Lehey To: Roelof Osinga Cc: Garance A Drosihn , j mckitrick , freebsd-questions@FreeBSD.ORG Subject: return(value) or return value? (was: style(9) question) Message-ID: <20010516124259.B83152@wantadilla.lemis.com> References: <20010515184940.A56109@dogma.freebsd-uk.eu.org> <20010516112824.B35292@wantadilla.lemis.com> <3B01EE40.4D2D6534@nisser.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <3B01EE40.4D2D6534@nisser.com>; from roelof@nisser.com on Wed, May 16, 2001 at 05:04:32AM +0200 Organization: LEMIS, PO Box 460, Echunga SA 5153, Australia Phone: +61-8-8388-8286 Fax: +61-8-8388-8725 Mobile: +61-418-838-708 WWW-Home-Page: http://www.lemis.com/~grog X-PGP-Fingerprint: 6B 7B C3 8C 61 CD 54 AF 13 24 52 F8 6D A4 95 EF Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Wednesday, 16 May 2001 at 5:04:32 +0200, Roelof Osinga wrote: > Greg Lehey wrote: >> >> On Tuesday, 15 May 2001 at 15:17:54 -0400, Garance A Drosihn wrote: >>> At 6:49 PM +0100 5/15/01, j mckitrick wrote: >>>> Why does style(9) put parentheses around return values? >>> >>> Apparently, some very early versions of C required this. >> >> Specifically, versions before about 1973. >> >> So why do we still do it? I don't know. > > Brian W. Kernighan and Dennis M. Ritchie, The C Programming Language > 1978 (!) published by Prentice Hall Software Series. I don't know what you're trying to say here. By the time this book was written, the parentheses were no longer required. > [note. This book was set in Times Roman and Courier 12 by the authors > using a Graphic Systems phototypesetter driven by a PDP-11/70 running > under the UNIX operating system. > > So why is it weird when I ask how to get (g|t)roff to generate PS A4, eh?] > > In Chapter 4 on page 68 they tell us: > > The /return/ statement is the mechanism for returning a value from the > called function to its caller. Any expression can follow /return/: > > /return (|expression|)/ > > where / denotes courier font and | italics. > > So why? Because ``THEY'' sayd so in 1978! ;) This appears to be an error. In Appendix A, which is definitive, on page 203, it states: return ; return expression ; I asked Dennis Ritchie about this some time back. Here's the reply: > Date: Fri, 11 Feb 2000 01:36:53 -0500 > From: dmr@plan9.bell-labs.com > To: grog@lemis.com > Subject: Re: 'return expression' or 'return (expression)'? > >> 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 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 Greg -- Finger grog@lemis.com for PGP public key See complete headers for address and phone numbers To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message