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,9f3d09bde7b33b5d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-04-08 12:04:07 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: jimmaureenrogers@worldnet.att.net (Jim Rogers) Newsgroups: comp.lang.ada Subject: Re: Pass by reference Date: 8 Apr 2004 12:04:05 -0700 Organization: http://groups.google.com Message-ID: <82347202.0404081104.33d05af0@posting.google.com> References: <19b0e504.0404080652.4eab9f80@posting.google.com> NNTP-Posting-Host: 209.194.156.4 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1081451046 4990 127.0.0.1 (8 Apr 2004 19:04:06 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 8 Apr 2004 19:04:06 +0000 (UTC) Xref: archiver1.google.com comp.lang.ada:6864 Date: 2004-04-08T12:04:05-07:00 List-Id: dan.r.mcleran@seagate.com (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? Ada provides some guidance to the compiler, but the general idea is that the compiler is free to choose the most efficient parameter passing mechanism for each instance. If you specify an parameter (of any type) as an IN parameter you will not be able to modify the array within the subprogram, no matter how the compiler chooses to pass the parameter. If you specify a parameter of any type as an OUT or IN OUT parameter you will be able to modify its value within the procedure. This is true even if the parameter is passed by value. > > 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. Tagged types are typically passed by reference no matter what the parameter mode. Why do you want to specify by value if you can specify IN mode? Do you want to be able to modify the value locally in the subprogram? In Ada you do that by copying the IN value to a local variable in the subprogram. In this manner you are forcing the creation of a local copy of the value, no matter how it was passed. The Ada approach is most efficient if you only want to read, but not write to, the IN parameter. It eliminates an unnecessary copy. If you do want to read and locally modify the parameter Ada forces you to explicitly make the copy implicitly made by C#, making your code no less efficient than C# in that case. Jim Rogers