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



LinkBack URL
About LinkBacks



CornedBee
Where do you learn about how the OS and the system deals with stack and heap memory and so on, i've never learned that in school but it seems to be nessesary knowledge if I want to really excel at C++.