While on Windows I had no problems, I was wondering if it's safe to delete a variable that's already NULL by standard. I want to make sure my code is portable without the need to add an if check every time I want to delete.
Printable View
While on Windows I had no problems, I was wondering if it's safe to delete a variable that's already NULL by standard. I want to make sure my code is portable without the need to add an if check every time I want to delete.
If deleting NULL is part of standard behaviour, then go ahead and do it.
If it doesn't work, then it's down to that specific version of your compiler rather than anything to do with your OS. Another compiler for the same OS would likely do the right thing.
The standard defines deleting a null pointer to be a noop. VC++6 didn't follow the standard there and created an access violation, but except for that one outdated compiler, I think pretty much all of them follow the standard.