home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!kithrup!hoptoad!decwrl!deccrl!bloom-beacon!eru.mt.luth.se!lunic!sunic!mcsun!Germany.EU.net!unido!starlab!mi
- From: mi@starlab.UUCP (Michael Hoennig)
- Newsgroups: comp.lang.c++
- Subject: Re: destruction of temporaries
- Keywords: temporaries,destruction,statements,block,early
- Message-ID: <3920@starlab.UUCP>
- Date: 19 Aug 92 06:36:38 GMT
- References: <BszApE.49v@world.std.com> <1992Aug17.073500.24115@ericsson.se> <23466@alice.att.com>
- Organization: StarDivision GmbH, D-2000 Hamburg, Germany
- Lines: 50
-
- In article <23466@alice.att.com> ark@alice.UUCP () writes:
- >
- > 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.
- In my opinion the result shouldn't be to destroy temporaries such early -
- and of cause not more early (before the end of the statement).
-
- >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.
-
- Why shorter, Andrew? Why not like all other automatic instances (those
- on the stack) at the end of the block? In this case everyone can exactly
- recocnize when the temporaries will be destroyes - and of cause too you
- can exactly determine the point of destruction, simply be creating
- additional blocks. As shown here:
-
- int foo()
- {
- Class a1, a2;
- { cout << a1+a2; } // immediately after using - destroy
- ... /// do more stuff - without the temporary
- }
-
- I think - the earlier temporaries will be destroyed, the more silent bugs
- will be in C++ programs. Of cause we can't destroy them too late, but there
- must be coosen a safe and determinable rule.
-
- Please, dont't destroy them immediatley. Many elegant constructions
- in C++ programs (as shown in examples in this news thread) won't be
- possible anymore.
-
- Adios
-
- --
- Michael Hoennig FAX: +49 40 23 646 550
- StarDivision GmbH Phone: +49 40 23 646 500
- Sachsenfeld 4 uucp: ...!unido!starlab!mi
- D-W-2000 Hamburg 1 domain: mi@starlab.uucp
-