home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12693 < prev    next >
Encoding:
Internet Message Format  |  1992-08-20  |  1.8 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Proposal: auto T&
  5. Date: 21 Aug 1992 03:00:40 GMT
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 39
  8. Message-ID: <171m8oINNdu7@early-bird.think.com>
  9. References: <1992Aug20.171342.3589@sunb10.cs.uiuc.edu> <9223406.29682@mulga.cs.mu.OZ.AU> <1992Aug20.213417.5690@sunb10.cs.uiuc.edu>
  10. NNTP-Posting-Host: gandalf.think.com
  11.  
  12. In article <1992Aug20.213417.5690@sunb10.cs.uiuc.edu> pjl@sparc10.cs.uiuc.edu (Paul Lucas) writes:
  13. >In <9223406.29682@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  14. >>What do you mean by "it's not reentrant"? Why not?
  15. >
  16. >*****>    Because the "slot" allocated in the caller would first receive
  17. >    the temporary generated by "stringfunction( b )" then it would
  18. >    be clobbered by "stringfunction( c )" 
  19.  
  20. I think the rest of us understood that enough temporaries would be
  21. allocated so that there would be no clobbering.
  22.  
  23. >    The problem with that is, what does the compiler do if a
  24. >    function returning an auto& calls itself?
  25.  
  26. That's what stack frames are for.  Each stack frame for the function would
  27. contain space for all the temporaries that are returned.
  28.  
  29. The easiest way to understand this is to transform the program into a
  30. version where the temporaries are explicit.  Thus,
  31.  
  32.     String a, b, c;            // also assume + has been overloaded
  33.     // ...
  34.     a = stringfunction( b ) + stringfunction( c );
  35.  
  36. is equivalent to:
  37.  
  38.     String a, b, c, temp1, temp2;
  39.     // ...
  40.     temp1 = stringfunction(b);
  41.     temp2 = stringfunction(c);
  42.     a = temp1 + temp2;
  43.  
  44. Your claim of non-reentrancy suggests that you think the temporaries would
  45. be static, not automatic.
  46. -- 
  47. Barry Margolin
  48. System Manager, Thinking Machines Corp.
  49.  
  50. barmar@think.com          {uunet,harvard}!think!barmar
  51.