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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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: controlnews3.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: "out" parameters Date: Sat, 29 May 2004 09:15:06 +0200 Organization: AdaCL Message-ID: <3624890.SfVk23Gvzd@linux1.krischik.com> References: <14098638.pGWFRt1ihv@linux1.krischik.com> Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1085814941 04 8446 1NuzG0+6qlcOBRR 040529 07:15:41 X-Complaints-To: usenet-abuse@t-online.de X-ID: TJYXdsZYrex3oM9StQnZcdXB7S64t2wdrVwschGbbHUI3729zl8b4T User-Agent: KNode/0.7.7 Xref: controlnews3.google.com comp.lang.ada:904 Date: 2004-05-29T09:15:06+02:00 List-Id: Jo wrote: > Martin Krischik wrote in message > news:<14098638.pGWFRt1ihv@linux1.krischik.com>... >> Jo wrote: >> >> > 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? >> >> It is not compiler dependent. There are rules. Within the rules the >> compiler will do what is best. >> >> If you need to force him to use a specific calling convetion you can use >> "pragma Convention" or "pragma Export" described in the chapter for >> interfacing with other languages. But don't do it unless you have too or >> for training. >> >> With Regards >> >> Martin > > > If the compiler, within the rules, does what it thinks it's the best, > it implies that it is, at least to a certain extent, compiler > dependent. > > If I have a record that contains 2 fields, I initialize the 1st field, > I then pass the record as an 'out' parameter to a subprogram. The > subprogram assigns a value to the 2nd field and returns. > If the record has neither elementary nor access type in it, then the > compiler may have the flexibility to decide how it wants to pass the > record. > The question is, what value should I expect for the 1st field in the > record when the subprogram returns? The first field is initialised to is default value - which might be undefined - the second to whatever you said. With "out" a brand new record is created and copied back into the one passed. The compiler might optimise on the amount of copy needed but this is what you should expect. If you have: procedure X (Ret : out Some_Type); function X return Some_Type; and both X will perform the same operations then X (Some_Var); Some_Var := X will be the same. Only that with Ada < AdaY0 you the procedure can be used for limited types and the function can not. Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com