Article View: net.lang.c
Article #9202Re: by-ref parameters, aggregate constants, etc
From: Tainter
Date: Mon, 25 Aug 1986 20:43
Date: Mon, 25 Aug 1986 20:43
52 lines
2453 bytes
2453 bytes
> >In article <6229@sun.uucp> guy@sun.uucp (Guy Harris) writes:
> >>This may, in fact, also be an argument for reference types a la C++; there,
> >>your routine "foo" would be written as
> >> foo(c) char &c; { ...
> I have no great love for this syntax either; but how else do you
> propose to add by-reference parameters? (I believe that by-reference
> parameters are, in general, bad, at least if I cannot tell from
> the caller that the parameter is modifiable. I would not add them
> at all. Clearly Bjarne Stroustrup and I disagree.)
> In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
The win for by-reference parameters is the syntax of their use in the callEE.
I do extensive personal programming in pascal and C. When rereading pascal
with by-reference parameters I do at times lose track of what is a var
parameter at the callER level but never at the callEE level. C fixes this
but at the expense of excessive clutter and confusion with pointers inside
the callEE.
I propose:
dowa(a)
int &a; /* this declares a to be a pointer to an whose use has
the syntax of an auto int. this is a pascal style var
parameter implementation of by-reference */
{
int b;
a = rand();
b = rand() + a;
return b;
}
main()
{
int sr,fr;
/* In the CALLER the pascal style var parameter implementation
gets superceded by explicit address of and pointer syntax */
sr = dowa(&fr); /* still required to pass address of */
printf("first random = %d, sum of two randoms = %d\n",fr,sr);
/* this would also be legal: */
pfr = malloc(sizeof (int));
sr = dowa(pfr);
printf("first random = %d, sum of two randoms = %d\n",*pfr,sr);
}
Basically it provides the same "pointer" syntax at the callER and
a friendly by-reference syntax at the callEE.
--j.a.tainter
Technical Details
Message-ID:
<2400@ihlpg.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!clyde!cbatt!cbosgd!ihnp4!ihlpg!tainterReferences:
<522@bunny.UUCP> <6229@sun.uucp> <161@BMS-AT.UUCP> <3100@umcp-cs.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!clyde!cbatt!cbosgd!ihnp4!ihlpg!tainter From: tainter@ihlpg.UUCP (Tainter) Newsgroups: net.lang.c Subject: Re: by-ref parameters, aggregate constants, etc Message-ID: <2400@ihlpg.UUCP> Date: Mon, 25-Aug-86 16:43:37 EDT Article-I.D.: ihlpg.2400 Posted: Mon Aug 25 16:43:37 1986 Date-Received: Tue, 26-Aug-86 18:48:07 EDT References: <522@bunny.UUCP> <6229@sun.uucp> <161@BMS-AT.UUCP> <3100@umcp-cs.UUCP> Distribution: net Organization: AT&T Bell Laboratories Lines: 52