Possible Duplicate:
Testing pointers for validity (C/C++)
If I have a pointer, like char* foo
, is there any way to determine if foo
points to a valid location in memory? (So, foo
is not NULL
, and delete
has not yet been called on it.)
No, there is not.
No. It's pretty much your responsibility to make sure you don't use dangling pointers.
However, one practice recommended by that link (I've seen some people use this, others hate it) is to immediately set the pointer to NULL
after you free/delete it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With