Path: utzoo!mnetor!uunet!husc6!uwvax!oddjob!gargoyle!ihnp4!inuxc!iuvax!pur-ee!uiucdcs!bradley!bucc2!brian From: brian@bucc2.UUCP Newsgroups: comp.lang.c Subject: Re: nasty evil pointers Message-ID: <13100004@bucc2> Date: 8 Mar 88 01:26:00 GMT References: <13100003@bucc2> Lines: 40 Nf-ID: #R:bucc2:13100003:bucc2:13100004:000:1548 Nf-From: bucc2.UUCP!brian Mar 7 19:26:00 1988 > /* Written 5:10 am Mar 7, 1988 by bucc2.UUCP!brian in bucc2:comp.lang.c */ > /* ---------- "nasty evil pointers" ---------- */ > We lose a lot of a time to pointers running off all over the place. > We are using Microsoft C 5.0 under MESS-DOS, and that means no control > of memory. We've tried using things like _nullcheck() and _heapwalk(), but > the don't help much. It would be nice if we could check every pointer as > it was used... something like > > void pointer_validate(p, n, f) > void *p; > int n; > char *f; After I posted my earlier note, I thought of a way to make this problem somewhat simpler... The follwing macro can be defined: #define VAL(p) (pointer_validate((p), __LINE__, __FILE__), (p)) Then all that needs to be done is to replace a pointer dereferences with *VAL(ptr), for example: *expr => *VAL(expr) expr->expr2 => VAL(expr)->expr2 Of course, the program still needs to know something about C to tell pointer dereferences from multiplication, and then there are more complex cases like: **expr => *VAL(*VAL(expr)) But this problem is much simpler. So does anyone know how to solve this simpler problem of putting a VAL macro around every pointer dereference? ............................................................................... When the going gets weird, the weird turn pro. Brian Michael Wendt UUCP: {cepu,ihnp4,uiucdcs,noao}!bradley!brian Bradley University ARPA: cepu!bradley!brian@seas.ucla.edu (309) 691-5175 ICBM: 40 40' N 89 34' W