Re: By value-result vs by reference

andrewd@apanix.apana.org.au (Andrew Dunstan)
Sun, 24 Apr 1994 02:20:51 GMT

          From comp.compilers

Related articles
By value-result vs by reference guerin@iro.umontreal.ca (1994-04-21)
Re: By value-result vs by reference graham@pact.srf.ac.uk (1994-04-21)
By value-result vs by reference ssimmons@convex.com (1994-04-21)
Re: By value-result vs by reference hbaker@netcom.com (1994-04-21)
Re: By value-result vs by reference Dik.Winter@cwi.nl (1994-04-21)
Re: By value-result vs by reference nebbe@lglsun.epfl.ch (1994-04-22)
Re: By value-result vs by reference andrewd@apanix.apana.org.au (1994-04-24)
Re: By value-result vs by reference hbaker@netcom.com (1994-04-23)
Re: By value-result vs by reference nebbe@lglsun.epfl.ch (1994-04-26)
Re: By value-result vs by reference Theo.Norvell@comlab.oxford.ac.uk (1994-04-26)
Re: By value-result vs. by reference pardo@cs.washington.edu (1994-04-28)
Re: By value-result vs by reference hbaker@netcom.com (1994-04-28)
Re: By value-result vs by reference anton@mips.complang.tuwien.ac.at (1994-04-29)
[2 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
From: andrewd@apanix.apana.org.au (Andrew Dunstan)
Keywords: design, comment
Organization: cleese.apana.org.au Public Access UNIX +61-8-3736006
References: 94-04-145
Date: Sun, 24 Apr 1994 02:20:51 GMT

guerin@iro.umontreal.ca (Frederic Guerin) writes:
>I would like to hear about call-by-value-result vs call-by-reference,
>which one is better ?


Henry G. Baker (hbaker@netcom.com) wrote:
: Unfortunately, due to significant differences in efficiency, many
: language designers weasel out at the last minute and allow implementations
: to defy a consistent semantics. The results of this weaselling are fast,
: unportable programs and slow, portable programs.


: The biggest weasel hole around is in Ada, which refuses to take a stand at
: all, and therefore if your program can tell the difference, it is
: 'erroneous'.


Scalars in Ada MUST be passed by value/result. No weaselling there!
Structured objects MAY be passed by reference, for fairly obvious
efficiency reasons, but, as you say, a program which can tell the
difference, i.e. which will produce different results depending on whether
or not the compiler passes arrays by reference, is erroneous.


Is this "weaselling"? Why should it be? Plenty of languages have things
which are implementation defined. A classic example is the order of
evaluation of operands. Try something like this with a whole bunch of C
compilers:


x = y == y++ ;


Sometimes x will be 1, sometimes 0. Were the designers of C weaselling?
Hardly.


Barring the presence of an exception, the only way that you can "tell the
difference" in Ada is to write a routine that has a side effect directly
modifying its parameters, i.e. by aliasing. If you write code like that
you deserve what you get. The language designers should not be required to
cater for idiots writing bad code.


Why use value/result? Well, when a subprogram exits via an exception, the
result is not copied back (at least in Ada), so you haven't corrupted your
actual parameter. This makes for rather cleaner semantics in the presence
of exceptions.


andrew dunstan
[Hey, some of my best friends are weasels. -John]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.