Re: Call of a destructor for NULL pointer
- From: "Vladimir Grigoriev" <vlad.moscow@xxxxxxx>
- Date: Tue, 22 Sep 2009 13:51:14 +0400
I have understood the problem. The previous night I played with Borland C++
5.0. Today I looked through generated assembler code and saw the following
delete p; // std::auto_ptr<Widget> p;
push 0x03
mov edx,[ebp+0x08]
push dword ptr[edx]
call Widget::~Widget()
~Widget()
push ebp
mov ebp,esp
cmp dword ptr[ebp+0x08],0x00
jz +0x22
....
pop ebp
ret
i.e. the Borland C++ 5.0 compiler inserts checking of the 'this' inside a
destructor. So in debug mode I saw that Widget destructor was called.
After that I thought about to change the auto_ptr destructor the following
way :)
~auto_ptr()
{
if ( the_p ) delete the_p;
}
Vladimir Grigoriev
"Scot T Brennecke" <ScotB@xxxxxxxxxxxxxxxxxx> wrote in message
news:uOE5fc1OKHA.4580@xxxxxxxxxxxxxxxxxxxxxxx
Sure, you'll get a destructor called for temporary auto_ptr abjects
because you passed the wp parameter by value, so a copy is made. But this
doesn't have anything to do with calling a destructor for a NULL pointer.
delete p does not call a destructor if p is NULL.
.
- Follow-Ups:
- Re: Call of a destructor for NULL pointer
- From: Mateusz Loskot
- Re: Call of a destructor for NULL pointer
- References:
- Call of a destructor for NULL pointer
- From: Vladimir Grigoriev
- Re: Call of a destructor for NULL pointer
- From: David Webber
- Re: Call of a destructor for NULL pointer
- From: Vladimir Grigoriev
- Re: Call of a destructor for NULL pointer
- From: Scot T Brennecke
- Call of a destructor for NULL pointer
- Prev by Date: Re: Call of a destructor for NULL pointer
- Next by Date: Can we pass FILE * across library
- Previous by thread: Re: Call of a destructor for NULL pointer
- Next by thread: Re: Call of a destructor for NULL pointer
- Index(es):
Relevant Pages
|