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 X-Google-Thread: 103376,ede2fcfbef7f3092 X-Google-Attributes: gid103376,public Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Nick Roberts" Newsgroups: comp.lang.ada Subject: Re: "out" parameters Date: Fri, 4 Jun 2004 22:59:40 +0100 Message-ID: <2ic9mcFl05rsU1@uni-berlin.de> References: X-Trace: news.uni-berlin.de bg7R8WgSBXiDGlzRBm22ZgOOjP4c/35KwCPq94NT+Z1+Y3fi0= X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 Xref: g2news1.google.com comp.lang.ada:1111 Date: 2004-06-04T22:59:40+01:00 List-Id: "Jo" wrote in message news:e26e273.0405201537.35ced9db@posting.google.com... > Does anyone happen to know whether an "out" parameter in Ada > is being passed by-copy or by-reference? > > If the parameter is a record with neither elementary nor access type > component in it, then is it true that whether the "out" parameter is > passed by-copy or by-reference is totally compiler dependent? I think that is true, yes. However, I think possibly you (Jo) should bear in mind that the parameter passing mechanism does not normally have any semantic significance in Ada, unlike many other languages. For example, in C: void foo(int bar, int &hum) { bar++; hum++; }; int a = 0; int b = 0; ... foo(a,b); will cause b to be incremented (to 1) but will not change a. In Ada: procedure Foo (Bar: in Integer; Hum: in out Integer) is begin Bar := Bar + 1; Hum := Hum + 1; end; will not compile. The compiler will complain that Bar is a constant, so it cannot be assigned to. If you were to write: type My_Rec_1 is record ... end record; X1: constant My_Rec_1 := ...; type My_Rec_2 is record A, B: My_Rec_1; end record; X2: My_Rec_2; procedure Init (Rec: out My_Rec_2) is begin Rec.A := X1; end; ... Init(X2); then at this point you can be sure that X2.A will have the value of X1 in it, regardless of the parameter passing mechanism. You cannot be sure what value X2.B has. Most of the time, Ada tries to minimise nasty surprises! In case you are curious, one situation in which the parameter passing method matters in Ada is when two tasks call a procedure, and their executions of the procedure overlap. If both tasks pass the same variable as a parameter, and the procedure could update the parameter, the effect on the variable could depend on whether it is passed by copy or by reference. The choice of mechanism might be a compiler choice. A dependency on a compiler choice in an Ada program is erroneous (if it is intended to be portable or long-lived), but such errors cannot generally be detected by the compiler. HTH -- Nick Roberts