[comp.lang.ada] ADA Compiler Query

gor@cs.strath.ac.uk (Gordon Russell) (02/11/91)

 Hi out there, 
  I am hoping that someone on the network can answer a compiler implementation
problem for me. The problem stems from my PhD research into compiler 
techniques. If we consider the following program extract...


variable1 : integer;

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;

My question is.......what is variable1 equal to at the end of MAIN?
There appears to be a number of options....either
   (1) 4
   (2) 12
   (3) Something wierd
   (4) Compiler dependent.

Evidentally, it is reliant on whether GET_RESULT operates on variable2
directly or indirectly. I am hoping that the results are compiler 
dependent. Does anyone have an ADA compiler who is willing to test this?
I am especially interested to hear from official sources (if they are
reading this), since I do not want to break any validation suite
program.

Reply either to this newsgroup or by email. I will post a concensus if
comments are mailed directly to me. Please no flames if this program is
not syntatically correct, as it is the mechanism which I am inquiring 
after. And yes, I do think that this is poor programming practice,
but when has that stopped anyone!

Thanx in advance.....Gordon Russell
                     gor@cs.strath.ac.uk

wayne@inmet.inmet.com (02/13/91)

The compiler actions are well defined.  According to the LRM (section 6.2:6)
for a scalar parameter (integers, etc) of mode IN OUT the value of the
formal parameter, variable2, is a copy of the actual parameter, variable1
and it in this case it should have the value of 10.  At the end of GET_RESULT
variable1 will be updated from variable2.  Mode IN OUT is not "call by
reference" for scalar types.

 1 procedure MAIN is
 2    variable1 : integer;
 3    result : integer;
 4 ----------------------------------------------------
 5 procedure GET_RESULT(variable2: in out integer) is
 6  begin
 7    variable1 := 2;
 8    variable2 := variable1 + variable2;
 9  end GET_RESULT;
10 ----------------------------------------------------
11 begin
12  variable1 := 10;
13  get_result(variable1);
14 end MAIN;

So at line 6 both variable1 and variable2 have the value of 10.
After line 7 is executed, variable1 has the value of 2, and variable2
still has the value of 10.

The answer should therefore be
   (2) 12

Wayne Wylupski
Intermetrics, Inc.