comp.lang.ada
 help / color / mirror / Atom feed
From: mfeldman@eesun.gwu.edu (Michael Feldman)
Subject: Re: ADA Compiling Query
Date: 12 Feb 91 19:01:29 GMT	[thread overview]
Message-ID: <2710@sparko.gwu.edu> (raw)
In-Reply-To: 5572@baird.cs.strath.ac.uk

In article <5572@baird.cs.strath.ac.uk> Gordon Russell <gor@cs.strath.ac.uk> writes:
>
>procedure MAIN is
>   variable1 : integer;
>   result : integer;
>----------------------------------------------------
> procedure GET_RESULT(variable2: in out integer) is
>  begin
>    variable1=2;
>    variable2=variable1 + variable2;
>  end GET_RESULT;
>----------------------------------------------------
> begin
>  variable1=10;
>  get_result(variable1);
> end MAIN;

Please don't take this as a flame, Gordon; I'm posting it for others' use as
well. The critique is not of the syntax errors, nor of the fact that this
classical aliasing problem is poor style (which you point out), but the fact
that the answer to this question is readily available in the LRM, namely
sect. 6.2, in which it states quite clearly that this parameter is passed by
copy-in/copy-out. This means that GET_RESULT is working on a local copy of
variable1 (in its alias as variable2). 

For a _scalar_ parameter, the parameter semantics is well-defined. For a
parameter of a _composite_ type, it's not: the implementation can choose
copy-in/copy-out _or_ reference passing. This would have made your question
more interesting.

Here's an exercise I give to my classes, when we discuss this stuff: for some
compiler you have access to, prove that the scalar passing is by value/result
(aka copy-in/copy-out), and write programs to demonstrate the behavior of
passing for composite types. Hint: most compilers use reference passing for
large arrays (common sense, no?); some use value/result for small arrays. If
the latter, find the "crossover".

[This exercise is to create a _purposely_ erroneous program: we _want_ its
behavior to depend on the mechanism :-)]

<WARNING: SERMON COMING>
The LRM is really a good source of information. Serious Ada folks should
have it and use it.
<HERE ENDETH THE SERMON>

Mike Feldman
-- 
Send compilers articles to compilers@iecc.cambridge.ma.us or
{ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.

  reply	other threads:[~1991-02-12 19:01 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-02-11 15:06 ADA Compiling Query Gordon Russell
1991-02-12 19:01 ` Michael Feldman [this message]
1991-02-13 21:16 ` Jeff Bartlett
1991-02-14 16:45   ` Michael Feldman
1991-02-15 23:09     ` Jim Showalter
1991-02-17  0:19       ` Reference vs. copy semantics in passing parameters Michael Feldman
1991-02-17 18:54         ` Erland Sommarskog
1991-02-18 18:41           ` Doug Smith
1991-02-18  0:36         ` Jim Showalter
1991-02-18  1:42           ` Michael Feldman
1991-02-18 18:49           ` Arthur Evans
1991-02-19  2:05             ` Michael Feldman
1991-02-18 13:10         ` madmats
1991-02-19 19:00           ` Robert I. Eachus
1991-05-16 13:51         ` Alex Blakemore
1991-05-17  8:19           ` Matthias Ulrich Neeracher
1991-05-17 13:44           ` Markku Sakkinen
1991-05-28  5:28           ` Kenneth Almquist
1991-02-18 14:33 ` ADA Compiling Query stt
     [not found] <5572@baird.cs.strath.ac.uk#  <20600085@inmet>
1991-02-21 20:40 ` Michael Feldman
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox