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: <1992Aug18.071116.3971@ericsson.se>
- Sender: news@ericsson.se
- Nntp-Posting-Host: falcon.ericsson.se
- Reply-To: jonas@beppe.ericsson.se
- Organization: Ericsson Telecom AB
- References: <23466@alice.att.com>
- Date: Tue, 18 Aug 1992 07:11:16 GMT
- Lines: 67
-
- In article 23466@alice.att.com, ark@alice.att.com (Andrew Koenig) writes:
- > In article <1992Aug17.073500.24115@ericsson.se> jonas@beppe.ericsson.se writes:
- >
- > > IMO temporaries should survive until end of statement.
- >
- > This treatment has two significant disadvantages:
- >
- > 1. If I break a statement up into several, it may
- > quietly change its meaning. Thus, for example, if
- > String::operator const char*() exists, and s and t are
- > of class String, then
- >
- > printf("%s\n", (const char*)(s+t));
- >
- > might work but
- >
- > const char* r = s + t;
- > printf("%s\n", r);
- >
- > might not.
-
- Here the programmer must be aware that a conversion takes place and should take
- necessary actions. Though, I agree it isn't obvious until you have had this bug.
-
- >
- > 2. It is a real pain to implement for statements that
- > generate temporaries inside conditionals. Thus, for
- > example, in x>0?f(p+q):r, if p+q generates a temporary,
- > and it was necessary to wait until the end of the statement
- > to destroy it, it would also be necessary to remember which
- > branch of the ?: was taken to decide whether or not to
- > destroy it. There are cases where this can add substantially
- > to execution time. Moreover, it greately complicates the
- > implementation of exception handling, because it makes it
- > impossible to have a static map from program counter value
- > to offsets of statics to destroy.
-
- I get very suspicious when I here about how difficult things are to do in a compiler, e.g.
- I can't accept that extra space in templates x<y<int> > which is claimed to be so difficult to solve.
- (I have never received so many replies as to the article where I claimed this to be a bug).
-
- Without any compiler experience I solved this in gcc with one days work. Think of all irritation
- it causes to forget this little space, and how relatively simple it can be alleviated.
-
- >
- > For these reasons, I think a shorter lifetime than end of statement
- > is appropriate for temporaries. Whether the committee will go that
- > way, however, remains to be seen.
-
- Perhaps end of statement is not the correct point for destruction of temporaries but I hope you agree
- that the small example I showed where:
-
- s2 = s1.sub(2,3);
-
- works, but not
-
- s2 = s1.sub(2,3).strip();
-
- is a bit to subtle to be acceptable.
-
- > --
- > --Andrew Koenig
- > ark@europa.att.com
-
-
- /jonas
-
-