You are not logged in.
Pages: 1
Hi,
Other than checking if pointer is NULL, is there any other proven methods of checking a pointer passed as parameter into a function call to make sure it's valid before we start dereference it and use it.
-Vincent
Offline
Unfortunately there is just no way of knowing if it is safe to dereference a pointer. That is why you should always initialize pointers to zero, and do the same when you have deleted the pointer. I've had some really nasty bugs when forgetting to do so.
Offline
You cannot verify pointer integrity locally within a function. However, there are tools that can catch some pointer errors statically or during runtime. valgrind is a popular one.
Offline
Also, it's generally a better idea to simply make it a precondition that pointers passed to a function are valid.
If for some reason you cannot do that (and I'm 99.9% sure you can), then your only other choice for a runtime validation is to change your program so that you use memory from a memory pool you manage yourself.
For this topic: consider the correctness of your program.
As soon as you start requiring fancy checks and special cases, you're most likely doing something wrong, or have taken a bad design choice.
You know you're paranoid when you start thinking random letters while typing a password.
A good post about vim
Python has no multithreading.
Offline
Pages: 1