Topic: Temporary lifetimes (was: .. about C++ .. all is pretty!)


Author: David Vandevoorde <daveed@vandevoorde.com>
Date: 1997/07/30
Raw View
Matt Austern wrote:
[...]
> That's not true.  The lifetime of temporary objects is not
> implementation defined, it is standardized.  It's described in section
> 12.2 of the draft C++ standard.

Let me play the devil's advocate ;-)
Which of the temporaries is destroyed first in the following?

 f(A(), B()); // A and B classes with nontrivial dtors

 Daveed
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Bjorn Fahller <Bjorn.Fahller@ebc.ericsson.se>
Date: 1997/07/30
Raw View
David Vandevoorde wrote:
>
> Let me play the devil's advocate ;-)
> Which of the temporaries is destroyed first in the following?
>
>         f(A(), B()); // A and B classes with nontrivial dtors

If I understand things correctly, the one that is constructed last :-)

A useless answer, yes, but not because the lifetime of temporaries is
not specified. The reason for the impossibility to determine this is
because the evaluation order of parameters is not specified.

As a side note, I woundn't very much approve of code whose behaviour
depends on this.
--
Bjorn Fahller                  Tel: +46 8 4220898 /
NA/EBC/DN/NT                   -------------------
Ericsson Business Networks AB / A polar bear is a rectangular
S-131 89 Stockholm/SWEDEN    /  bear after a coordinate transform
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: "Paul D. DeRocco" <pderocco@ix.netcom.crud.com>
Date: 1997/07/31
Raw View
David Vandevoorde wrote:
>
> Let me play the devil's advocate ;-)
> Which of the temporaries is destroyed first in the following?
>
>         f(A(), B()); // A and B classes with nontrivial dtors

It doesn't matter. The point is that neither will be destroyed until
after f returns.

--

Ciao,
Paul

(Please remove the extra "crud" from the return address,
which has been altered to foil junk mail senders.)
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]