home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!microsoft!hexnut!jimad
- From: jimad@microsoft.com (Jim Adcock)
- Subject: Re: destruction of temporaries
- Message-ID: <1992Aug17.233923.14077@microsoft.com>
- Date: 17 Aug 92 23:39:23 GMT
- Organization: Microsoft Corporation
- References: <46140@sunquest.UUCP>
- Lines: 29
-
- In article <46140@sunquest.UUCP> bill@sunquest.UUCP (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.
-
- When an unnamed temporary is assigned to a reference, then the unnamed
- temporary is no longer unnamed. I believe this should mean that the lifetime
- of the temporary then becomes that of the reference, but its easy to find
- lots of compilers that disagree with this.
-
- The bottom line is, if you DO rely on unnamed temporaries to do anything,
- you WILL be disappointed in the code generated by one or more compilers.
-
- Some years after the ansi committee decides on the life times of temporaries,
- what it means to give a name to a previously unnamed temporary [by assigning
- it to a reference] whether functions return by copy or by value, when compilers
- can create temporaries, and when compilers can leave them out, and how many
- of these temporaries are created or not, what sequences points are and where
- they exist, what "const" means, and what "volatile" means....
-
- .... when the committee decides on these things, if ever, and then some
- years later when C++ compiler reliably implement the standard, THEN and only
- then can you, in practice, rely on the behavior of temporaries. UNTIL THEN,
- good luck.
-
- Today, if you want to write portable code, rely on named temporaries.
-
-