Re: ADA Compiling Query (Michael Feldman)
12 Feb 91 19:01:29 GMT

          From comp.compilers

Related articles
ADA Compiling Query (Gordon Russell) (1991-02-11)
Re: ADA Compiling Query (1991-02-12)
Re: ADA Compiling Query (1991-02-13)
Re: ADA Compiling Query (1991-02-13)
| List of all articles for this month |

Newsgroups: comp.lang.ada,comp.compilers
From: (Michael Feldman)
Followup-To: comp.lang.ada
Keywords: Ada, question
Organization: The George Washington University, Washington D.C.
References: <>
Date: 12 Feb 91 19:01:29 GMT

In article <> Gordon Russell <> writes:
>procedure MAIN is
> variable1 : integer;
> result : integer;
> procedure GET_RESULT(variable2: in out integer) is
> begin
> variable1=2;
> variable2=variable1 + variable2;
> 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 :-)]

The LRM is really a good source of information. Serious Ada folks should
have it and use it.

Mike Feldman

Post a followup to this message

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