home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!kithrup!hoptoad!decwrl!mips!carbon!news.cs.indiana.edu!syscon!gator!fang!att!allegra!alice!ark
- From: ark@alice.att.com (Andrew Koenig)
- Newsgroups: comp.lang.c++
- Subject: Re: Proposal: auto T&
- Message-ID: <23494@alice.att.com>
- Date: 20 Aug 92 13:06:34 GMT
- Article-I.D.: alice.23494
- References: <1992Aug19.234913.622@tfs.com>
- Reply-To: ark@alice.UUCP ()
- Organization: AT&T Bell Laboratories, Murray Hill NJ
- Lines: 33
-
- In article <1992Aug19.234913.622@tfs.com> eric@tfs.com (Eric Smith) writes:
-
- > Much recent discussion about destruction of temporaries suggests a
- > better way to solve the whole problem, and to allow returning references
- > to temporaries from functions.
-
- > auto String& stringfunction(const String& input)
- > {
- > // Calculate/create a new temporary or named automatic String
- > // and return a reference to it.
- > }
-
- > The "auto" in the function return value type tells the compiler to allocate
- > the space for that automatic in the stack frame of the caller, instead of
- > the stack frame of the called function.
-
- What's wrong with this?
-
- String stringfunction(const String& input)
- {
- // Calculate/create a new temporary or named automatic String
- // and return a copy of it.
- }
-
- A smart compiler will allocate space for the result in the stack frame of the
- caller, instead of the stack frame of the called function. A number of
- C++ implementations already do this.
-
- This technique has the advantage of being easy to understand and
- getting the right answer from all existing C++ implementations.
- --
- --Andrew Koenig
- ark@europa.att.com
-