nasty evil pointers

brian at bucc2.UUCP brian at bucc2.UUCP
Tue Mar 8 11:26:00 AEST 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 at seas.ucla.edu
  (309) 691-5175            ICBM: 40 40' N  89 34' W



More information about the Comp.lang.c mailing list