nasty evil pointers

Dave White backstro at silver.bacs.indiana.edu
Thu Mar 10 10:46:25 AEST 1988


In article <13100003 at bucc2> brian at bucc2.UUCP writes:
>
>It would be nice if we could check every pointer as
>it was used...
>
>
>If pointer
>pointed, say, into the operating system or the text space, the function
>would print a message and exit(). Otherwise it would return.
>
>Without source to the compiler it could
>be a major project. Does anybody know a way this could be done, perhaps with
>something like lex?
>
Lattice C 3.0 (and, I suppose, more recent versions) allow the size of
the stack and the size of the heap to be specified at runtime -- one
uses an argument of the form
   =ssize/heapsize
which the runtime startup routine digests before calling main().
Given such a beast, Lattice can provide isxxxx() functions that
determine whether a passed pointer points within an expected space.
However, the programmer must call them explicitly.

This makes it possible to determine when a wild pointer endangers the
machine.  It has the disadvantage that the proper heapsize might need to
be fudged, as well as the stacksize....  developing code for 8086's anf
friends is painful enough...

The sanest way to do what you want automatically is to build it into the
compiler itself.  Because compilers frequently call internal functions not made
available to the user, and because of the difficulty of cases like the
one you mention, it just isn't practical to write a pre-processor for
this -- you'd be halfway to rewriting the compiler!
>---
>  When the going gets weird, the weird turn pro.
No, they just bring out an Optimizing Turbo 5.0 version :-)
--
backstro at silver.bacs.indiana.edu



More information about the Comp.lang.c mailing list