home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12678 < prev    next >
Encoding:
Internet Message Format  |  1992-08-20  |  1.6 KB

  1. Path: sparky!uunet!kithrup!hoptoad!decwrl!mips!carbon!news.cs.indiana.edu!syscon!gator!fang!att!allegra!alice!ark
  2. From: ark@alice.att.com (Andrew Koenig)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Proposal: auto T&
  5. Message-ID: <23494@alice.att.com>
  6. Date: 20 Aug 92 13:06:34 GMT
  7. Article-I.D.: alice.23494
  8. References: <1992Aug19.234913.622@tfs.com>
  9. Reply-To: ark@alice.UUCP ()
  10. Organization: AT&T Bell Laboratories, Murray Hill NJ
  11. Lines: 33
  12.  
  13. In article <1992Aug19.234913.622@tfs.com> eric@tfs.com (Eric Smith) writes:
  14.  
  15. > Much recent discussion about destruction of temporaries suggests a
  16. > better way to solve the whole problem, and to allow returning references
  17. > to temporaries from functions.
  18.  
  19. > auto String& stringfunction(const String& input)
  20. > {
  21. >    // Calculate/create a new temporary or named automatic String
  22. >    // and return a reference to it.
  23. > }
  24.  
  25. > The "auto" in the function return value type tells the compiler to allocate
  26. > the space for that automatic in the stack frame of the caller, instead of
  27. > the stack frame of the called function.
  28.  
  29. What's wrong with this?
  30.  
  31.     String stringfunction(const String& input)
  32.     {
  33.        // Calculate/create a new temporary or named automatic String
  34.        // and return a copy of it.
  35.     }
  36.  
  37. A smart compiler will allocate space for the result in the stack frame of the
  38. caller, instead of the stack frame of the called function.  A number of
  39. C++ implementations already do this.
  40.  
  41. This technique has the advantage of being easy to understand and
  42. getting the right answer from all existing C++ implementations.
  43. -- 
  44.                 --Andrew Koenig
  45.                   ark@europa.att.com
  46.