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 3 9589
Songling wrote: 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
--
Artie Gold -- Austin, Texas http://it-matters.blogspot.com http://www.cafepress.com/goldsays
Songling wrote: 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.
--
Sumit Rajan <su*********@gmail.com>
"Songling" <ya******@nortelnetworks.com> wrote in message news:<co**********@zcars0v6.ca.nortel.com>... 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: qazmlp |
last post by:
Say, ptr=0 / ptr=NULL.
delete ptr; //is safe
// Is
delete ptr; // also safe ?
|
by: Nitin Bhardwaj |
last post by:
Hi all,
It is said that C++ is a strongly typed language and thus a type-safe
language (unlike C). So how does one explain the following behaviour :
int main(void)
{
char *p = NULL;
p = "A...
|
by: Christopher Pisz |
last post by:
currently my node is like so with everything public:
class Quadtree_Node
{
public:
Quadtree_Node(Quadtree_Node * parent, Bounding_Box & bounds);
~Quadtree_Node();
void Subdivide(float...
|
by: Squid Seven |
last post by:
I create a pointer to an item:
CardSession *cardSession;
Then, later, I use new to create an instance of the item and assign it
to that pointer:
cardSession = new CardSession();
In...
|
by: gary |
last post by:
Hi,
We all know the below codes are dangerous:
{
int *p = new int;
delete p;
delete p;
}
And we also know the compilers do not delete p if p==NULL.
So why compilers do not "p = NULL"...
|
by: ais523 |
last post by:
I use this function that I wrote for inputting strings. It's meant to
return a pointer to mallocated memory holding one input string, or 0 on
error. (Personally, I prefer to use 0 to NULL when...
|
by: Nindi73 |
last post by:
Hi,
I am in need of a deep copy smart pointer (Boost doesn't provide one)
which doesnt require the contained types to have a virtual copy
constructor. I wrote a smart pointer class that I think...
|
by: Felix Kater |
last post by:
Hi,
if I want to make sure that neither the pointer arg nor the value to
which it points to is NULL: Is solution (a) safe -- or does it have to
be like (b) ?
Felix
void f(int* p){
/* (a)...
|
by: Jon Slaughter |
last post by:
Is it safe to remove elements from an array that foreach is working on?
(normally this is not the case but not sure in php) If so is there an
efficient way to handle it? (I could add the indexes to...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |