home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!masscomp!peora!tarpit!fang!att!allegra!alice!ark
- From: ark@alice.att.com (Andrew Koenig)
- Newsgroups: comp.lang.c++
- Subject: Re: destruction of temporaries
- Message-ID: <23466@alice.att.com>
- Date: 17 Aug 92 12:24:36 GMT
- Article-I.D.: alice.23466
- References: <BszApE.49v@world.std.com> <1992Aug17.073500.24115@ericsson.se>
- Reply-To: ark@alice.UUCP ()
- Organization: AT&T Bell Laboratories, Liberty Corner NJ
- Lines: 38
-
- 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.
-
- 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.
-
- 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.
- --
- --Andrew Koenig
- ark@europa.att.com
-