home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:12280 comp.std.c++:1078
- Path: sparky!uunet!sunquest!bill
- From: bill@sunquest.UUCP (Bill Raves)
- Newsgroups: comp.lang.c++,comp.std.c++
- Subject: destruction of temporaries
- Message-ID: <46140@sunquest.UUCP>
- Date: 12 Aug 92 23:31:55 GMT
- Followup-To: comp.lang.c++
- Organization: Sunquest Information Systems, Tucson
- Lines: 26
-
- We have encountered some widely different behavior in compilers (e.g.
- DEC C++ and cfront) with respect to the destruction of unnamed temporaries
- in contexts where a pointer or reference to object data is returned.
- We realize that compiler implementors have been given latitude in this
- area (see $12.2 of the ARM) and that the ANSI C++ standards committee is
- discussing this issue. We also realize that the manifestations of this
- behavior may introduce subtle bugs in code. The question is "How can
- we prevent these problems from getting into production code?".
-
- One suggestion is to promulgate stylistic guidelines which caution
- against troublesome usage. 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. Henricson & Nyquist suggest "Do not write code which is
- dependent on the lifetime of a temporary object" but this seems too
- vague, especially for novice programmers, and seems to require us to
- know the details of the implementation. What *specific* guidelines
- would you suggest for avoiding potential problems with unnamed tem-
- poraries?
-
-
- --
- Bill Raves bill@sunquest.com
- Sunquest Information Systems sunquest!bill@arizona.edu
- Tucson, AZ {arizona,uunet}!sunquest!bill
-