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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Proposal: auto T&
  5. Message-ID: <1992Aug21.015710.21692@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1992Aug19.234913.622@tfs.com>
  10. Date: Fri, 21 Aug 1992 01:57:10 GMT
  11. Lines: 51
  12.  
  13. In article <1992Aug19.234913.622@tfs.com> eric@tfs.com (Eric Smith) writes:
  14. >
  15. >Much recent discussion about destruction of temporaries suggests a
  16. >better way to solve the whole problem, and to allow returning references
  17. >to temporaries from functions.
  18. >
  19. >auto String& stringfunction(const String& input)
  20. >{
  21. >   // Calculate/create a new temporary or named automatic String
  22. >   // and return a reference to it.
  23. >}
  24. >
  25. >The "auto" in the function return value type tells the compiler to allocate
  26. >the space for that automatic in the stack frame of the caller, instead of
  27. >the stack frame of the called function.
  28. >
  29.  
  30.     But you can already do this:
  31.  
  32.     String f(...);
  33.  
  34. Just return a value instead of a reference.
  35. Some compilers (Borland for example) pass the address of the return
  36. memory to the procedure allowing direct construction without
  37. copying in some cases.
  38.  
  39. The real problem is that the C 'return expr' syntax is faulty.
  40. There is no 'handle' or 'name' like 'this' on which to
  41. make the return value. The Pascal syntax does not have
  42. this problem (the function name is used as a variable
  43. representing the return value)
  44.  
  45.     function f(integer x):integer
  46.     begin
  47.         f=10;
  48.     end
  49.  
  50. In C one could just use 'result':
  51.  
  52.     int f(int x){result=10;}
  53.  
  54. However this would not work properly if 'result' had to
  55. be constructed as an object.
  56.  
  57.  
  58.  
  59. -- 
  60. ;----------------------------------------------------------------------
  61.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  62.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  63. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  64.