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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9f3d09bde7b33b5d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-04-08 21:03:02 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn51feed!worldnet.att.net!attbi_s01.POSTED!not-for-mail From: "Steve" Newsgroups: comp.lang.ada References: <19b0e504.0404080652.4eab9f80@posting.google.com> Subject: Re: Pass by reference 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: NNTP-Posting-Host: 24.20.111.157 X-Complaints-To: abuse@comcast.net X-Trace: attbi_s01 1081483381 24.20.111.157 (Fri, 09 Apr 2004 04:03:01 GMT) NNTP-Posting-Date: Fri, 09 Apr 2004 04:03:01 GMT Organization: Comcast Online Date: Fri, 09 Apr 2004 04:03:01 GMT Xref: archiver1.google.com comp.lang.ada:6879 Date: 2004-04-09T04:03:01+00:00 List-Id: I am only aware of one (obscure) case in Ada where passing by reference versus passing by value makes a difference. It has come up on this newsgroup before. If you pass the same value to a procedure as both an "in" and an "in out" parameter, changes to the "in out" version may or may not effect the value of the "in" mode value depending on the compilers choice of whether to pass by reference or by value. Here is a small program that illustrates the case: with Ada.Text_Io; with Ada.Integer_Text_Io; procedure By_Ref_Vs_By_Value is package Text_Io renames Ada.Text_IO; package Integer_Text_Io renames Ada.Integer_Text_Io; type int_array_type is array( 1 .. 10 ) of integer; procedure Show_Both( a : Integer; b : in out integer ) is begin Text_Io.Put( "Initial a" ); Integer_Text_Io.Put( a ); Text_Io.New_Line; b := b + 1; Text_Io.Put( "Final a" ); Integer_Text_Io.Put( a ); Text_Io.New_Line; end Show_Both; procedure Show_Both( a : int_array_type; b : in out int_array_type ) is begin Text_Io.Put( "Initial a" ); Integer_Text_Io.Put( a(1) ); Text_Io.New_Line; b(1) := b(1) + 1; Text_Io.Put( "Final a" ); Integer_Text_Io.Put( a(1) ); Text_Io.New_Line; end Show_Both; int_value : Integer := 0; int_array_value : int_array_type := ( others => 0 ); begin Show_Both( int_value, int_value ); Show_Both( int_array_value, int_array_value ); end By_Ref_Vs_By_Value; BTW: I have never experienced this in practice. In Ada I have found that if you just let the compiler to its thing, it is generally the right thing. Steve (The Duck) "Dan McLeran" wrote in message news:19b0e504.0404080652.4eab9f80@posting.google.com... > I am investigating using Ada for a project at work and I have a > question I hope someone can answer. If I am interpreting the RM > section 6.2 correctly, an array of elementary types does not meet the > criteria of a by-reference type. But, when looking at the disassembly, > it seems that passing an array of elementary types to a function as an > in-mode parameter is passing by reference. Does this mean that an > array of elementary types is an unspecfied type? > > A 2nd part to my question is: Does Ada automatically pass tagged types > by reference no matter what mode the parameter is specfied (in, in > out, or out)? The language RM 6.2 seems to suggest this is so. If so, > does this mean that there is no way to pass a tagged type by value? I > believe C# works this way without programmer intervention. > > I am using Aonix's ObjectAda V7.2.2, by the way. I have not tried GNAT > for comparison. > > Thanks, > > Dan McLeran