From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!newsfeed101.telia.com!nf02.dk.telia.net!news.tele.dk!news.tele.dk!small.news.tele.dk!bnewspeer01.bru.ops.eu.uu.net!emea.uu.net!fi.sn.net!newsfeed1.tdcnet.fi!news.song.fi!not-for-mail Date: Tue, 17 Nov 2009 12:40:57 +0200 From: Niklas Holsti Organization: Tidorum Ltd User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Passing the same actual as both in and out formal parameters? References: <1fbe454c-52b0-408b-9159-982fc019a53c@j19g2000yqk.googlegroups.com> In-Reply-To: <1fbe454c-52b0-408b-9159-982fc019a53c@j19g2000yqk.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4b027ddd$0$3877$4f793bc4@news.tdc.fi> NNTP-Posting-Host: 81.17.205.61 X-Trace: 1258454493 news.tdc.fi 3877 81.17.205.61:60879 X-Complaints-To: abuse@tdcnet.fi Xref: g2news1.google.com comp.lang.ada:8122 Date: 2009-11-17T12:40:57+02:00 List-Id: Ludovic Brenta wrote: > Consider: > > type T is tagged private; > procedure P (A : in T; B : out T) is separate; > Object : T; > begin > P (A => Object, B => Object); > > This seems legal but I suspect the execution might lead to bugs if P > reads and writes components of A and B in arbitrary order, e.g. I think this situation is defined in RM 6.2(12) where A and B are defined as "distinct access paths" to the same object. It is a bounded error if the parameter passing mechanism is not specified, but (by default) should work as expected when the parameters are passed by reference. > type T is tagged record > L, M : Integer; > end record; > > procedure P (A : in T; B : out T) is > begin > B.L := A.M; -- does this change A.L too? Yes, as far as I understand RM 6.2(12). > B.M := A.L; -- bug: A.L has been clobbered, now B.M = B.L? I believe so. > 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? Yes, if you expect A to be immutable during the execution of P. There is a Note to RM 6.2(12), which is 6.2(13): "A formal parameter of mode in is a constant view (see 3.3); it cannot be updated within the subprogram body". But I think this means only that the "in" mode access path to this object cannot be used to update it. It does not mean that the value of the object cannot change at all, due to assignments from other access paths. If P is mean to return B as A with L and M swapped, you should use an aggregate assignment, B := (L => A.M, M => A.L). -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .