home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!sdd.hp.com!elroy.jpl.nasa.gov!ames!agate!tfs.com!tfs.com!eric
- From: eric@tfs.com (Eric Smith)
- Subject: Proposal: auto T&
- Message-ID: <1992Aug19.234913.622@tfs.com>
- Organization: TFS
- Date: Wed, 19 Aug 1992 23:49:13 GMT
- Lines: 29
-
-
- 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.
-
- The compiler can also do the same kind of thing implicitly within a function.
- That is, allocate the space for each temporary in the outermost stack frame
- containing references to it. It doesn't need an explicit "auto" for that
- because it can derive it during the compile.
-
- Costs/benefits: The compiler needs to do a little more work to handle auto T&
- and the auto might need to be accessed via a pointer because it might not be
- possible for the compiler to know its stack offset at compile time. The
- benefits to the programmer might be a lot bigger than the obvious benefits
- seem at first. Beginning C++ programmers almost aways complain about the
- problems caused by lack of this functionality, which they almost always
- intuitively assume without even thinking about the implications. A lot of
- function interfaces would become much neater. A lot of the complaints about
- lack of garbage collection are really motivated by lack of this functionality.
-