|
Boost : |
From: Chris Just (cpjust_at_[hidden])
Date: 2005-02-15 00:21:18
Jonathan Turkanis wrote:
>>> Declaring a function to take an argument of type auto_ptr<...> is
>>> one way to signal that ownership is being transfered to the
>>> function. It also ensures that the managed object will be deleted,
>>> unless the function takes explicit steps to cause a leak. Passing
>>> raw pointers defeats this system.
>>
>> Yes, this is true if you're calling a function that you wrote and
>> compiled yourself, but if you're calling a 3rd party API that you
>> didn't compile yourself, that can be dangerous (or so I've been told).
>
> Dangeous how? Actually the opposite is true: if you declare such a function to
> take a raw pointer,
I'm not an expert with compilers so I'll tell you how it was explained to me. Different compilers
could take the same C++ code and compile it into different machine code, causing function pointers
to shift. When you pass an object that was compiled on one machine to a function that was
compiled on another machine, you can't be sure that the object will be deleted properly.
> callers might think they still own the pointer after calling
> the function, or the function might not clean up the resource properly.
That's what documentation is for.
__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk