Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 May 2001 12:43:00 +0930
From:      Greg Lehey <grog@lemis.com>
To:        Roelof Osinga <roelof@nisser.com>
Cc:        Garance A Drosihn <drosih@rpi.edu>, j mckitrick <jcm@FreeBSD-uk.eu.org>, freebsd-questions@FreeBSD.ORG
Subject:   return(value) or return value? (was: style(9) question)
Message-ID:  <20010516124259.B83152@wantadilla.lemis.com>
In-Reply-To: <3B01EE40.4D2D6534@nisser.com>; from roelof@nisser.com on Wed, May 16, 2001 at 05:04:32AM %2B0200
References:  <20010515184940.A56109@dogma.freebsd-uk.eu.org> <p05100e0bb727313f1395@[128.113.24.47]> <20010516112824.B35292@wantadilla.lemis.com> <3B01EE40.4D2D6534@nisser.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010516124259.B83152>