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-09 05:53:40 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: dan.r.mcleran@seagate.com (Dan McLeran) Newsgroups: comp.lang.ada Subject: Re: Pass by reference Date: 9 Apr 2004 05:53:39 -0700 Organization: http://groups.google.com Message-ID: <19b0e504.0404090453.3c276b@posting.google.com> References: <19b0e504.0404080652.4eab9f80@posting.google.com> <54077117.Uc4Ikxz6le@linux1.krischik.com> NNTP-Posting-Host: 192.55.20.36 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1081515220 8112 127.0.0.1 (9 Apr 2004 12:53:40 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 9 Apr 2004 12:53:40 +0000 (UTC) Xref: archiver1.google.com comp.lang.ada:6900 Date: 2004-04-09T05:53:39-07:00 List-Id: > Good Ada compiler will do what is best. So "array (1 .. 2) of Character" is > likely to be passed by value while "array (1 .. 10_000) of Integer" is > probably passed by reference. And some Ada compilers might even use pass by > register. Not sure what you mean by 'pass by register'. Maybe each value of a 2-element array are loaded into registers and then read by the calling function? > > This might sound strange to a C, C++ or C# programmer. Like giving up > control. There are things humans can do better then computers but there are > also things computers can do better then humans - and counting is is among > those. The compiler knows much better how many registers are available, how > large the type is, how long it takes to copy and so on. It's not too foreign of idea to me because I use a C++ library to do essentially the same thing. The Boost Call Traits Library is a template library that chooses the optimal parameter passing convention based on type. Since the C++ project I have been working on makes heavy use of templates, I am used to leaving it up to someone/something else to choose the best calling convention. > > You say what you need (in, out, in out) and the compiler will choose the > optimal way to fullfill you which. This is what I want to solidify in my brain. Alot of people posting replies seem to say that the compiler has more freedom than the RM specifies. If most Ada compilers are conforming, I would assume that the compiler only has freedom for unspecified types. By-reference and by-values types must be passed as stated in RM 6.2. > > > 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. > > They are in deed allways passed by reference. That's done to enable > dispaching. Rermember: all native procedures of a tagged type are "virtual". > > Two ways around that behavior: > > 1st: for any tagged type X there is indefinite type X'Class. X'Class is an > indefinite but untagged type so RM 6.2 does not apply here. > > 2nt: RM 6.2 does not apply to a non native procedure. That is a procedure > in another package. > > With Regards > > Martin