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.
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law