home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: Proposal: auto T&
- Message-ID: <1992Aug21.015710.21692@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <1992Aug19.234913.622@tfs.com>
- Date: Fri, 21 Aug 1992 01:57:10 GMT
- Lines: 51
-
- In article <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.
- >
-
- But you can already do this:
-
- String f(...);
-
- Just return a value instead of a reference.
- Some compilers (Borland for example) pass the address of the return
- memory to the procedure allowing direct construction without
- copying in some cases.
-
- The real problem is that the C 'return expr' syntax is faulty.
- There is no 'handle' or 'name' like 'this' on which to
- make the return value. The Pascal syntax does not have
- this problem (the function name is used as a variable
- representing the return value)
-
- function f(integer x):integer
- begin
- f=10;
- end
-
- In C one could just use 'result':
-
- int f(int x){result=10;}
-
- However this would not work properly if 'result' had to
- be constructed as an object.
-
-
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-