comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Passing the same actual as both in and out formal parameters?
Date: Tue, 17 Nov 2009 03:26:29 -0800 (PST)
Date: 2009-11-17T03:26:29-08:00	[thread overview]
Message-ID: <044632e0-e40c-4c47-ab56-189f4ae0c15b@u7g2000yqm.googlegroups.com> (raw)
In-Reply-To: 81utdh.otp.ln@hunter.axlog.fr

Jean-Pierre Rosen wrote on comp.lang.ada:
> Ludovic Brenta a écrit :
>
>  procedure P (A : in T; B : out T) is
>> begin
>>    B.L := A.M; -- does this change A.L too?
> Yes
>>    B.M := A.L; -- bug: A.L has been clobbered, now B.M = B.L?
>> end P;
>
>> My concern stems from the fact that T is tagged (I cannot change
>> that), so Object is passed by reference as both A and B.
>
>> Am I right to be concerned?
>
> Depend on what your concern is ;-)
> The semantic is well defined: tagged types are by-reference type. If you
> want to swap two fields of different parameters of the same type, use a
> local variable.

My exampled was heavily simplified; the actual type has about a
hundred components and the procedure P is a little more complex than
swapping components :)

But thanks for the responses, Niklas and Jean-Pierre. They confirm my
suspicion.

--
Ludovic Brenta.



  reply	other threads:[~2009-11-17 11:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-17  9:50 Passing the same actual as both in and out formal parameters? Ludovic Brenta
2009-11-17 10:31 ` Jean-Pierre Rosen
2009-11-17 11:26   ` Ludovic Brenta [this message]
2009-11-17 13:13     ` Jean-Pierre Rosen
2009-11-17 16:07       ` Ludovic Brenta
2009-11-18 10:00         ` Jean-Pierre Rosen
2009-11-17 10:40 ` Niklas Holsti
2009-11-17 16:26 ` Adam Beneschan
2009-11-17 21:25   ` Randy Brukardt
2009-11-18  0:11     ` Jeffrey R. Carter
2009-11-18  0:23       ` Adam Beneschan
2009-11-18  3:47         ` Jeffrey R. Carter
replies disabled

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