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=-0.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a88a78b31443d1a9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-02-26 06:18:53 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!wn14feed!worldnet.att.net!199.45.49.37!cyclone1.gnilink.net!spamkiller2.gnilink.net!nwrdny03.gnilink.net.POSTED!0f19ed38!not-for-mail From: "Frank J. Lhota" Newsgroups: comp.lang.ada References: <5f59677c.0402260600.3c27ad66@posting.google.com> Subject: Re: in-out and out parameters X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: Date: Thu, 26 Feb 2004 14:18:52 GMT NNTP-Posting-Host: 141.154.50.15 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny03.gnilink.net 1077805132 141.154.50.15 (Thu, 26 Feb 2004 09:18:52 EST) NNTP-Posting-Date: Thu, 26 Feb 2004 09:18:52 EST Xref: archiver1.google.com comp.lang.ada:5849 Date: 2004-02-26T14:18:52+00:00 List-Id: "Evangelista Sami" wrote in message news:5f59677c.0402260600.3c27ad66@posting.google.com... > hello > > i have this program : > ==================== > procedure Test is > > task T is > entry E(I : out Integer; > J : in out Integer); > end T; > task body T is > begin > accept E(I : out Integer; > J : in out Integer) do > I := 1; > J := J * I; > J := J * J; > end E; > end; > > I : Integer := 10; > > begin > T.E(I, I); > Put_Line(Integer'Image(I)); > end; > ==================== > The output is 1. > I thought that, as I and J were passed by references, when i call E > with the > same variables, I and J denote the same object. so i was expecting to > get 100 in output. > If someone had a clear explanation i would be very thankful. Actually, you are probably getting this result precisely BECAUSE call by reference is being used. With call by reference, the assignment statement I := 1; in the "accept" statement will set Test.I to 1 as well. After this assignment, both the E parameters I and J will be 1, and hence I and J will return 1. This is not meant to be an indictment of call by reference. The real problem is that the entry call itself is confusing: if the values computed for the I and J parameters are different, which value should end up in Test.I? A more straightforward example, assume we have the procedure procedure Foo( L : out Integer; R : out Integer ) is begin L := 1; R := 2; end Foo; and an integer variable I, what is the value of I after the call Foo( I, I ); This is not the sort of question that should be burdening those who maintain your code. Avoid these confusing procedure / entry calls and the issue of calling mechanism goes away.