comp.lang.ada
 help / color / mirror / Atom feed
From: vsnyder@gyre.jpl.nasa.gov (Van Snyder)
Subject: Function result
Date: 1997/06/25
Date: 1997-06-25T00:00:00+00:00	[thread overview]
Message-ID: <5os5r8$4ud@netline.jpl.nasa.gov> (raw)
In-Reply-To: 19970619161801.MAA18772@ladder02.news.aol.com


In article <19970619161801.MAA18772@ladder02.news.aol.com>, johnherro@aol.com (John Herro) writes:
|> bobduff@world.std.com (Robert A Duff) writes:
|> > Of course, for functions, Ada doesn't allow you to set the result
|> > without doing a return.  Which I've sometimes found annoying.
|> 
|> But you can set a local variable Result in as many places as you want
|> and later return Result.  Isn't that as good?  I do it all the time.

This _works_ but it would be nice if you didn't need to trust the compiler
to optimize away the assignments to Result.

It doesn't seem so bad in Ada, with the explicit copy-out model of returning
function results, because you're only doubling the cost of returning the
function result.

The copy-out model, however, causes other headaches.  In particular, you
can't return a limited type, except by the "return by reference" kludge.

In Pascal and Fortran (at least) one returns a function result by assigning
to the result variable (default name = function name in Fortran 95).  The
Fortran standard is silent on _how_ function results are returned.  For
composite results (e.g. structures, arrays, character strings), most compilers
pass the address where the function result is to land as a "hidden argument."
In this way, the syntactic device of assigning to the function result
_really_is_ assigning directly to the function result -- no extra copying
involved.

By the way, this would eliminate the problem about returning a limited
type in Ada.

In the next standardization of Ada, I suggest allowing an optional "name:"
after "return" in a function header.  This would imply four things:
1.  The client is expected to supply the address where the function result
    is desired as a "hidden argument".
2.  The function result is materialized directly in the place the client
    wants it, without any copying.
3.  Since there's no copying going on outside the function, it would be OK
    to allow returning a limited type.
4.  In the function, the result would be materialized by storing into the
    result variable, not by mentioning the value in a "return" statement.
    The program could do this piece-by-piece in the case of a composite
    result.

-- 
What fraction of Americans believe   |  Van Snyder
Wrestling is real and NASA is fake?  |  vsnyder@math.jpl.nasa.gov




  reply	other threads:[~1997-06-25  0:00 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-11  0:00 GOTO considered necessary (reworked) Samuel Mize
1997-06-11  0:00 ` Bryce Bardin
1997-06-12  0:00 ` Michael F Brenner
1997-06-17  0:00   ` Robert Dewar
1997-06-17  0:00     ` Robert A Duff
1997-06-20  0:00       ` Robert Dewar
1997-06-21  0:00         ` Robert A Duff
1997-06-21  0:00           ` Robert Dewar
1997-06-12  0:00 ` Anonymous
1997-06-12  0:00   ` Robert Dewar
1997-06-12  0:00     ` John G. Volan
1997-06-13  0:00       ` Robert A Duff
1997-06-16  0:00         ` John G. Volan
1997-06-17  0:00           ` Robert Dewar
1997-06-17  0:00             ` Robert A Duff
1997-06-18  0:00               ` Spam Hater
1997-06-20  0:00               ` Robert Dewar
1997-06-21  0:00                 ` Robert A Duff
1997-06-21  0:00                   ` Robert Dewar
1997-06-20  0:00               ` Robert Dewar
1997-06-25  0:00               ` Wolfgang Gellerich
1997-06-25  0:00                 ` Michael F Brenner
1997-06-26  0:00                   ` Wolfgang Gellerich
1997-06-25  0:00                 ` Samuel T. Harris
1997-06-19  0:00             ` Karel Th�nissen
1997-06-19  0:00               ` Karel Th�nissen
1997-06-23  0:00               ` John G. Volan
1997-06-23  0:00                 ` Robert Dewar
1997-06-24  0:00                   ` Brian Rogoff
1997-06-25  0:00                   ` Featuritis not always bad (was re: GOTO considered necessary) Karel Th�nissen
1997-06-26  0:00                     ` Robert Dewar
1997-06-26  0:00                       ` Karel Th�nissen
1997-06-23  0:00                 ` GOTO considered necessary (reworked) Spam Hater
1997-06-25  0:00                 ` Karel Th�nissen
1997-06-23  0:00             ` John G. Volan
1997-06-17  0:00           ` Robert I. Eachus
1997-06-17  0:00           ` Robert A Duff
1997-06-25  0:00             ` Van Snyder
1997-07-21  0:00           ` Shmuel (Seymour J.) Metz
1997-06-12  0:00   ` John G. Volan
1997-06-16  0:00     ` Anonymous
1997-06-13  0:00 ` Robert A Duff
1997-06-14  0:00   ` Robert Dewar
1997-06-16  0:00     ` Robert A Duff
1997-06-17  0:00       ` Spam Hater
1997-06-17  0:00         ` Robert A Duff
1997-06-19  0:00           ` Spam Hater
1997-06-17  0:00         ` Robert Dewar
1997-06-17  0:00           ` Spam Hater
1997-06-17  0:00           ` Robert A Duff
1997-06-19  0:00             ` John Herro
1997-06-25  0:00               ` Van Snyder [this message]
1997-06-27  0:00                 ` Function result Robert Dewar
1997-06-27  0:00                 ` Jon S Anthony
1997-06-20  0:00             ` GOTO considered necessary (reworked) Robert Dewar
1997-06-16  0:00     ` Spam Hater
1997-06-17  0:00       ` Robert Dewar
1997-06-17  0:00         ` Spam Hater
1997-06-14  0:00   ` Samuel Mize
1997-06-14  0:00     ` Matthew Heaney
1997-06-14  0:00   ` Samuel Mize
1997-06-16  0:00 ` Anonymous
1997-06-16  0:00   ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox