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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,99222a5bd46ef3c9 X-Google-Attributes: gid103376,public From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: Function result Date: 1997/06/27 Message-ID: #1/1 X-Deja-AN: 252946902 References: <19970619161801.MAA18772@ladder02.news.aol.com> <5os5r8$4ud@netline.jpl.nasa.gov> Organization: New York University Newsgroups: comp.lang.ada Date: 1997-06-27T00:00:00+00:00 List-Id: Van Snyder says <> Oh dear, this is very confused. First, about trusting the compiler to optimize away the assignments to Result. Most compilers in any case have only one copy of the epilog in a function, and all return statements share it. For example, with GCC: procedure f is b,c,d : Boolean; function g return boolean is begin if b then return c; else return d; end if; end; function h return boolean is result : Boolean; begin if b then result := c; else result := d; end if; return result; end; begin null; end; The functions g and h generate identical code. It would be surprising to anyone who knows something about compilers if this were NOT the case. There is no doubling of costs anywhere, to guess that there might be is simply based on some kind of inaccurate model of code generation. Second, Ada does not require copy-out except for scalars, where in any case it is more efficient (and typically used in most Fortran compilers for example. It cannot be used in Pascal, but that often *damages* the efficiency of compiled code in a Pascal compiler, since call by reference is less efficient than call by copy for things that fit in registers. In fact Ada is very similar to Fortran when it comes to parameters that do not fit in registers, it allows the compiler to pass either by reference or by copy in/copy out. An Ada compiler will choose the most efficient method, and typically any large argument will be passed by reference. And yes, in the case where the result is fixed size (always true in Pascal and Fortran, not, of course, always true in Ada), a standard technique is for the caller to pass the address where the result is to be stored. Your conception that this is not possible in Ada is just wrong (for example, this is typically the way that GNAT returns results, and it is the way anyone would expect fixed-length resluts to be returned) Finally your comments on limited types show further misunderstanding. The "difficulties" on returning limited types have nothing at all to do with some kind of implementation problem (which as per above does not exist anyway), but rather there is a fundamental semantic issue, which is that limitedness is there to control copying (consider for example the case of a self-referential access discriminant). Since copying must be controlled, the semantics of returning a limited type must be dealt with very carefully in the language -- this is purely a semantic issue, not an implementation issue. I suggest reading the Ada 95 Rationale for a better understanding of what limited types are all about. As for the suggestions at the end of your message for the next version of Ada, they are irrelevant, since they are based on misconceptions, and make no sense in a context of understanding (a) the parameter passing rules in Ada (b) the typical implemenmtation approaches (c) the semantics of limited types. In particular, the suggestion of a syntactic device for labeling the returned value seems entirely undesirable.