comp.lang.ada
 help / color / mirror / Atom feed
From: harrison@software.org (Tim Harrison)
Subject: Parameter passing mechanisms
Date: 22 Feb 89 12:28:35 GMT	[thread overview]
Message-ID: <8902221418.AA16453@ajpo.sei.cmu.edu> (raw)

Mats Weber asks:  

> Question: is the following program erroneous ?
> 
>    procedure Is_This_Program_Erroneous is
> 
>       type Vector is array (1..5) of Float;
> 
>       A_Vector : Vector := (0.35, 0.67, 1.8, 2.0, 7.7);
> 
>       procedure Add (V : in Vector; W : in out Vector) is
>       begin
>          for I in 1..5 loop
>             W(I) := V(I) + W(I);
>          end loop;
>       end Add;
> 
>    begin
>       Add(A_Vector, A_Vector);
>    end Is_This_Program_Erroneous;

> But according to LRM 6.2(13) - which is a note and as such is not part of
> the standard - the program is erroneous because there are multiple access
> paths to A_Vector during the call Add(A_Vector, A_Vector);, and therefore
> V is undefined after the assignment W(1) := V(1) + W(1);

The program in question is not erroneous.  LRM 6.2(13) says that "the value
of the formal is undefined after updating the actual other than by updating
formal."  In the example program the actual is A_Vector and the formals are
V and W. The example program is only updating the formal (W) not the actual
(A_Vector).  If the program were

   procedure Is_This_Program_Erroneous is
      type Vector is array (1..5) of Float;
      A_Vector : Vector := (0.35, 0.67, 1.8, 2.0, 7.7);
      procedure (V : in Vector) is
      begin
         for I in 1..5 loop
            A_Vector(I) := A_Vector(I) + V(I);
         end loop;
      end Add;
   begin
      Add(A_Vector);
   end Is_This_Program_Erroneous;

the program would be erroneous (according to LRM 6.2(13)), because the actual
(A_Vector) would be updated other than through the formal (V).

-- Tim Harrison
Software Productivity Consortium  Phone:   (703) 742-7113
SPC Building                      CSnet:   harrison@software.org
2214 Rock Hill Road               ARPAnet: harrison@ajpo.sei.cmu.edu
Herndon, Virginia  22070

             reply	other threads:[~1989-02-22 12:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1989-02-22 12:28 Tim Harrison [this message]
  -- strict thread matches above, loose matches on Subject: below --
1989-02-23 13:08 Parameter passing mechanisms Mats Weber
1989-02-20 16:38 Mats Weber
replies disabled

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