home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12671 < prev    next >
Encoding:
Text File  |  1992-08-20  |  2.4 KB  |  61 lines

  1. Newsgroups: comp.lang.c++
  2. 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
  3. From: pjl@sparc10.cs.uiuc.edu (Paul Lucas)
  4. Subject: Re: Proposal: auto T&
  5. Message-ID: <1992Aug20.213417.5690@sunb10.cs.uiuc.edu>
  6. Sender: news@sunb10.cs.uiuc.edu
  7. Organization: University of Illinois at Urbana-Champaign
  8. References: <1992Aug19.234913.622@tfs.com> <1992Aug20.171342.3589@sunb10.cs.uiuc.edu> <9223406.29682@mulga.cs.mu.OZ.AU>
  9. Date: Thu, 20 Aug 1992 21:34:17 GMT
  10. Lines: 49
  11.  
  12. In <9223406.29682@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  13.  
  14. >pjl@sparc10.cs.uiuc.edu (Paul Lucas) writes:
  15.  
  16. >>In <1992Aug19.234913.622@tfs.com> eric@tfs.com (Eric Smith) writes:
  17. >>
  18. >>>Much recent discussion about destruction of temporaries suggests a
  19. >>>better way to solve the whole problem, and to allow returning references
  20. >>>to temporaries from functions.
  21. >>
  22. >>>auto String& stringfunction(const String& input)
  23. >>>{
  24. >>>   // Calculate/create a new temporary or named automatic String
  25. >>>   // and return a reference to it.
  26. >>>}
  27. >>
  28. >>>The "auto" in the function return value type tells the compiler to allocate
  29. >>>the space for that automatic in the stack frame of the caller, instead of
  30. >>>the stack frame of the called function.
  31. >>
  32. >>*****>    It's not reentrant.
  33. >>
  34. >>    String a, b, c;            // also assume + has been overloaded
  35. >>    // ...
  36. >>    a = stringfunction( b ) + stringfunction( c );
  37.  
  38. >Huh?
  39.  
  40. >What do you mean by "it's not reentrant"? Why not?
  41.  
  42. *****>    Because the "slot" allocated in the caller would first receive
  43.     the temporary generated by "stringfunction( b )" then it would
  44.     be clobbered by "stringfunction( c )" and clobbered yet again by
  45.     the temporary generated by operator+, assuming it also used this
  46.     proposed technique.  This assumes that there is one "slot"; a
  47.     compiler-writer could count the number of times an auto& is
  48.     called in the same expression and reserve that many slots so
  49.     that none would get clobbered.
  50.  
  51.     The problem with that is, what does the compiler do if a
  52.     function returning an auto& calls itself?  Or two such functions
  53.     calling each other recursively?  The proposed semantics says that
  54.     the slot goes in the caller; well if a function is itself the
  55.     caller, you've got problems because you can't know ahead of time
  56.     how many slots to allocate.
  57. -- 
  58.     - Paul J. Lucas                University of Illinois    
  59.       AT&T Bell Laboratories        at Urbana-Champaign
  60.       Naperville, IL            pjl@cs.uiuc.edu
  61.