home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!mcsun!sunic!ericom!falcon!jonas
- From: jonas@beppe.ericsson.se (Jonas Nygren)
- Subject: Re: destruction of temporaries
- Message-ID: <1992Aug17.073500.24115@ericsson.se>
- Sender: news@ericsson.se
- Nntp-Posting-Host: falcon.ericsson.se
- Reply-To: jonas@beppe.ericsson.se
- Organization: Ericsson Telecom AB
- References: <BszApE.49v@world.std.com>
- Date: Mon, 17 Aug 1992 07:35:00 GMT
- Lines: 52
-
-
- In article 49v@world.std.com, pkturner@world.std.com (Prescott K Turner) writes:
- >
- > Bill Raves writes:
- > > For example, Jim Adcock has suggested
- > > (<70784@microsoft.UUCP>) "NEVER rely on unnamed temporaries to do
- > > anything...", but this would seem to erode the expressiveness of the
- > > language: constructs like "foo(x + y)" and "foo()[i]" would no longer
- > > be permissible.
- >
- > I second Adcock's advice. Actually, those constructs can be made to
- > work at the expense of some extra implementation effort, and some
- > execution cost. But the cost is not an impediment if it's being compared
- > to code which is not portable to the platforms one needs.
- >
- > What the programmer must beware (in the absence of garbage
- > collection) is pointers and references that refer to unnamed objects.
- > The standards committee may eventually mandate that these objects
- > hang around somewhat longer, but not indefinitely.
- > Classes which rely on such pointers entail pitfalls. Late destruction
- > of temporaries (as in cfront) reduces but does not eliminate
- > the problem.
-
- IMO temporaries should survive until end of statement. At least they should not be destroyed
- as early as in gcc-2.x. In C you can write:
-
- X *p;
- a = (p+10)->f();
-
- where (p+10) will survive through the call. In gcc-2.x I wrote a small string class which had
- a member function 'string sub(int pos, int len)' which results in a temporary. I could do
-
- s2 = s.sub(2,3);
-
- but not
-
- s2 = s.sub(2,3).strip();
-
- because the temporary representing 's.sub(2,3)' was destroyed before tmp.strip(). This is kind of
- confusing.
-
- So let temporaries live until end of statement.
-
- > --
- > Prescott K. Turner, Jr.
- > 13 Burning Tree Rd., Natick, Massachusetts USA
- > Internet: pkturner@world.std.com
-
-
-
- /jonas
-
-