I'm pretty sure that doing:
is perfectly safe, and is just a no-op. Yet everywhere I look, I keep seeing code like this:Code:delete NULL;
WHY? The if guard isn't necessary, right? (Obviously it's good practice to assign a pointer to NULL after deleting it, but there's still no point in the if statement.) So why do people keep doing this? Is it still considered good practice (if so, why?), or is it simply the case that most C++ programmers think that deleting NULL is undefined?Code:int* ptr; ... if (ptr) { delete ptr; }
Just