safe to delete null pointer?

S

Songling

Hi gurus,

Just learnt from my co-worker that it's safe to delete a null pointer. I
tried it on sun box
(and linux), nothing bad happens. So it seems to be true. But does it apply
to all platforms?

Also if I delete a pointer twice, and don't nullify the pointer after the
first delete, it's going
to trap. If I do the nullify, no trap. Does it just confirm that it's safe
to delete null pointer?

Btw I ran my test on SunOS 5.8 and Linux 2.4.18-3.

Thanks for your reply!

Songling
 
A

Artie Gold

Songling said:
Hi gurus,

Just learnt from my co-worker that it's safe to delete a null pointer. I
tried it on sun box
(and linux), nothing bad happens. So it seems to be true. But does it apply
to all platforms?

Also if I delete a pointer twice, and don't nullify the pointer after the
first delete, it's going
to trap. If I do the nullify, no trap. Does it just confirm that it's safe
to delete null pointer?

Btw I ran my test on SunOS 5.8 and Linux 2.4.18-3.

Thanks for your reply!

Songling
Calling delete on a null pointer is a no-op -- and, by the standard, no
problem. Of course, the fact that you're deleting a null pointer may
indicate the existence of a bug in your program -- but not necessarily.

HTH,
--ag
 
S

Sumit Rajan

Songling said:
Hi gurus,

Just learnt from my co-worker that it's safe to delete a null pointer. I
tried it on sun box
(and linux), nothing bad happens. So it seems to be true. But does it apply
to all platforms?

Also if I delete a pointer twice, and don't nullify the pointer after the
first delete, it's going
to trap. If I do the nullify, no trap. Does it just confirm that it's safe
to delete null pointer?


Deleting a null pointer is safe. 5.3.5/2 of the Standard:

"In either alternative, if the value of the operand of delete is the
null pointer the operation has no effect."

Regards,
Sumit.
 
S

Stuart Gerchick

Songling said:
Hi gurus,

Just learnt from my co-worker that it's safe to delete a null pointer. I
tried it on sun box
(and linux), nothing bad happens. So it seems to be true. But does it apply
to all platforms?

Also if I delete a pointer twice, and don't nullify the pointer after the
first delete, it's going
to trap. If I do the nullify, no trap. Does it just confirm that it's safe
to delete null pointer?

Btw I ran my test on SunOS 5.8 and Linux 2.4.18-3.

Thanks for your reply!

Songling

Deleting a null poiner is fine. It will have no effect and will behave as expected
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top