If I had a dime for every time I've seen this macro in use, today I would be coding just for fun:
#define SAFE_DELETE(p) if ((p) != NULL) { delete (p); (p) = NULL; }
Why do programmers insist in keep using this macro when delete
checks for null? Is is because it sets the pointer to null at the end? Then why not at least rewrite it and remove the redundant check:
#define SAFE_DELETE(p) { delete (p); (p) = NULL; }
Still, it doesn't seem like a good practice.
NULL
checks withdelete
andfree()
. I suspect the fact that these checks are harmless make them justifiable in the minds of those who haven't read the documentation.