home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!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.213417.5690@sunb10.cs.uiuc.edu>
- Sender: news@sunb10.cs.uiuc.edu
- Organization: University of Illinois at Urbana-Champaign
- References: <1992Aug19.234913.622@tfs.com> <1992Aug20.171342.3589@sunb10.cs.uiuc.edu> <9223406.29682@mulga.cs.mu.OZ.AU>
- Date: Thu, 20 Aug 1992 21:34:17 GMT
- Lines: 49
-
- In <9223406.29682@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
-
- >pjl@sparc10.cs.uiuc.edu (Paul Lucas) writes:
-
- >>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 );
-
- >Huh?
-
- >What do you mean by "it's not reentrant"? Why not?
-
- *****> Because the "slot" allocated in the caller would first receive
- the temporary generated by "stringfunction( b )" then it would
- be clobbered by "stringfunction( c )" and clobbered yet again by
- the temporary generated by operator+, assuming it also used this
- proposed technique. This assumes that there is one "slot"; a
- compiler-writer could count the number of times an auto& is
- called in the same expression and reserve that many slots so
- that none would get clobbered.
-
- The problem with that is, what does the compiler do if a
- function returning an auto& calls itself? Or two such functions
- calling each other recursively? The proposed semantics says that
- the slot goes in the caller; well if a function is itself the
- caller, you've got problems because you can't know ahead of time
- how many slots to allocate.
- --
- - Paul J. Lucas University of Illinois
- AT&T Bell Laboratories at Urbana-Champaign
- Naperville, IL pjl@cs.uiuc.edu
-