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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!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: <1992Aug21.041354.7852@sunb10.cs.uiuc.edu>
  6. Sender: news@sunb10.cs.uiuc.edu
  7. Organization: University of Illinois at Urbana-Champaign
  8. References: <1992Aug20.171342.3589@sunb10.cs.uiuc.edu> <9223406.29682@mulga.cs.mu.OZ.AU> <1992Aug20.213417.5690@sunb10.cs.uiuc.edu> <171m8oINNdu7@early-bird.think.com>
  9. Distribution: usa
  10. Date: Fri, 21 Aug 1992 04:13:54 GMT
  11. Lines: 48
  12.  
  13. In <171m8oINNdu7@early-bird.think.com> barmar@think.com (Barry Margolin) writes:
  14.  
  15. >In article <1992Aug20.213417.5690@sunb10.cs.uiuc.edu> pjl@sparc10.cs.uiuc.edu (Paul Lucas) writes:
  16. >>In <9223406.29682@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  17. >>>What do you mean by "it's not reentrant"? Why not?
  18. >>
  19. >>*****>    Because the "slot" allocated in the caller would first receive
  20. >>    the temporary generated by "stringfunction( b )" then it would
  21. >>    be clobbered by "stringfunction( c )" 
  22.  
  23. >I think the rest of us understood that enough temporaries would be
  24. >allocated so that there would be no clobbering.
  25.  
  26. >>    The problem with that is, what does the compiler do if a
  27. >>    function returning an auto& calls itself?
  28.  
  29. >That's what stack frames are for.  Each stack frame for the function would
  30. >contain space for all the temporaries that are returned.
  31.  
  32. >The easiest way to understand this is to transform the program into a
  33. >version where the temporaries are explicit.  Thus,
  34.  
  35. >    String a, b, c;            // also assume + has been overloaded
  36. >    // ...
  37. >    a = stringfunction( b ) + stringfunction( c );
  38.  
  39. >is equivalent to:
  40.  
  41. >    String a, b, c, temp1, temp2;
  42. >    // ...
  43. >    temp1 = stringfunction(b);
  44. >    temp2 = stringfunction(c);
  45. >    a = temp1 + temp2;
  46.  
  47. >Your claim of non-reentrancy suggests that you think the temporaries would
  48. >be static, not automatic.
  49.  
  50. *****>    You're right; I stand corrected.  What I was thinking was that
  51.     the return-value _always_ was in the first caller of a recursive
  52.     calling sequence; I forgot to make the mental leap where yet
  53.     another slot would be created in the next stack frame just like
  54.     everything else.
  55.  
  56.     Apologies for any confusion.
  57. -- 
  58.     - Paul J. Lucas                University of Illinois    
  59.       AT&T Bell Laboratories        at Urbana-Champaign
  60.       Naperville, IL            pjl@cs.uiuc.edu
  61.