Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!gatech!mcnc!duke!helios!apte From: apte@helios.cs.duke.edu (Jitendra Apte) Newsgroups: comp.lang.c Subject: Pointer Question. Keywords: checking pointers. Message-ID: <14454@duke.cs.duke.edu> Date: 10 May 89 15:28:08 GMT Sender: news@duke.cs.duke.edu Lines: 35 I like to test pointers passed to routines at the beginning of the routine. I currently use a macro called CK_PTR() as follows. -------------------------------------------------------------------------- /* Use only if pointer is not expected to be NULL */ #define CK_PTR(_p_) {\ if (!(_p_)) {\ fprintf(stderr, "NULL pointer\n");\ exit(1);\ }\ }\ void routine(p) struct xyz_s * p; { CK_PTR(p); ... ... } -------------------------------------------------------------------------- This works fine while checking for NULL pointers. However, there are times when, due to some other bug in the program under develpment, pointers point out into space, nowhere in particular : eg. p = 0x2 Is there a better way of checking pointers so as to detect such problems? Seems difficult, because ideally the macro would have to know the limits of address space which are "legal". Fangs. Jitendra. (Internet) apte@cs.duke.edu; (UUCP) {decvax|ihnp4|allegra}!duke!apte "Let us save the kid from abortion, so that he can grow up to steal bread, rob banks and murder people. Then we can kill him in the electric chair".