Re: different behavour of printf() on dos and linux
Hyman Rosen wrote:
Pete Becker wrote:
In other words, we agree that the order of evaluation is not the only
solution to the auto_ptr example. That is, it's not "exactly about order
of evaluation".
No. To solve the auto_ptr problem, you need to specify
that the arguments to a function must be evaluated in
an order, with a sequence point between each evaluation.
For the last time: sequence points are sufficient. If each argument is
fully evaluated before moving on to another argument, the auto_ptr
problem is solved even if the order of evaluation is not specified.
As a reminder, the code in question is this:
#include <memory>
typedef std::auto_ptr<int> api;
void f(api, api) { }
int main() { f(api(new int(1)), api(new int(2))); }
And the problem is that the compiler is allowed to make both new calls
before constructing either api object. If the second new throws an
exception, the memory allocated by the first new is leaked.
If the compiler is required to call the corresponding api constructor
immediately after the call to new, then this code works, regardless of
the order in which the two api objects are constructed.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]