by-ref parameters, aggregate constants, etc
Tainter
tainter at ihlpg.UUCP
Tue Aug 26 06:43:37 AEST 1986
> >In article <6229 at sun.uucp> guy at 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
More information about the Comp.lang.c
mailing list