home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!usc!sdd.hp.com!ux1.cso.uiuc.edu!m.cs.uiuc.edu!sunb10.cs.uiuc.edu!sparc10.cs.uiuc.edu!pjl
- From: pjl@sparc10.cs.uiuc.edu (Paul Lucas)
- Subject: Re: Proposal: auto T&
- Message-ID: <1992Aug20.171342.3589@sunb10.cs.uiuc.edu>
- Sender: news@sunb10.cs.uiuc.edu
- Organization: University of Illinois at Urbana-Champaign
- References: <1992Aug19.234913.622@tfs.com>
- Date: Thu, 20 Aug 1992 17:13:42 GMT
- Lines: 41
-
- In <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.
-
- *****> It's not reentrant.
-
- String a, b, c; // also assume + has been overloaded
- // ...
- a = stringfunction( b ) + stringfunction( c );
-
- >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.
- --
- - Paul J. Lucas University of Illinois
- AT&T Bell Laboratories at Urbana-Champaign
- Naperville, IL pjl@cs.uiuc.edu
-